- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# VTSReader.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 "..\..\..\decss\VobFile.h"
    00024 #include "vtsreader.h"
    00025 #include "..\..\..\DSUtil\DSUtil.h"
    00026
    00027 #ifdef REGISTER_FILTER
    00028
    00029 const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
    00030 {
    00031         {&MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG2_PROGRAM},
    00032 };
    00033
    00034 const AMOVIESETUP_PIN sudOpPin[] =
    00035 {
    00036         {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
    00037 };
    00038
    00039 const AMOVIESETUP_FILTER sudFilter[] =
    00040 {
    00041         {&__uuidof(CVTSReader), L"VTS Reader", MERIT_UNLIKELY, countof(sudOpPin), sudOpPin}
    00042 };
    00043
    00044 CFactoryTemplate g_Templates[] =
    00045 {
    00046         {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CVTSReader>, NULL, &sudFilter[0]}
    00047 };
    00048
    00049 int g_cTemplates = countof(g_Templates);
    00050
    00051 STDAPI DllRegisterServer()
    00052 {
    00053         if(GetVersion()&0x80000000)
    00054                 return E_NOTIMPL;
    00055
    00056         SetRegKeyValue(
    00057                 _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{773EAEDE-D5EE-4fce-9C8F-C4F53D0A2F73}"),
    00058                 _T("0"), _T("0,12,,445644564944454F2D565453")); // "DVDVIDEO-VTS"
    00059
    00060         SetRegKeyValue(
    00061                 _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{773EAEDE-D5EE-4fce-9C8F-C4F53D0A2F73}"),
    00062                 _T("Source Filter"), _T("{773EAEDE-D5EE-4fce-9C8F-C4F53D0A2F73}"));
    00063
    00064         return AMovieDllRegisterServer2(TRUE);
    00065 }
    00066
    00067 STDAPI DllUnregisterServer()
    00068 {
    00069         DeleteRegKey(_T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{773EAEDE-D5EE-4fce-9C8F-C4F53D0A2F73}"));
    00070
    00071         return AMovieDllRegisterServer2(FALSE);
    00072 }
    00073
    00074 extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID);
    00075
    00076 BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
    00077 {
    00078     return DllEntryPoint((HINSTANCE)hModule, dwReason, 0); // "DllMain" of the dshow baseclasses;
    00079 }
    00080
    00081 #endif
    00082
    00083 //
    00084 // CVTSReader
    00085 //
    00086
    00087 CVTSReader::CVTSReader(IUnknown* pUnk, HRESULT* phr)
    00088         : CAsyncReader(NAME("CVTSReader"), pUnk, &m_stream, phr, __uuidof(this))
    00089 {
    00090         if(phr) *phr = S_OK;
    00091
    00092         if(GetVersion()&0x80000000)
    00093         {
    00094                 if(phr) *phr = E_NOTIMPL;
    00095                 return;
    00096         }
    00097 }
    00098
    00099 CVTSReader::~CVTSReader()
    00100 {
    00101 }
    00102
    00103 STDMETHODIMP CVTSReader::NonDelegatingQueryInterface(REFIID riid, void** ppv)
    00104 {
    00105     CheckPointer(ppv, E_POINTER);
    00106
    00107         return
    00108                 QI(IFileSourceFilter)
    00109                 __super::NonDelegatingQueryInterface(riid, ppv);
    00110 }
    00111
    00112 // IFileSourceFilter
    00113
    00114 STDMETHODIMP CVTSReader::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
    00115 {
    00116         if(!m_stream.Load(pszFileName))
    00117                 return E_FAIL;
    00118
    00119         m_fn = pszFileName;
    00120
    00121         CMediaType mt;
    00122         mt.majortype = MEDIATYPE_Stream;
    00123         mt.subtype = MEDIASUBTYPE_MPEG2_PROGRAM;
    00124         m_mt = mt;
    00125
    00126         return S_OK;
    00127 }
    00128
    00129 STDMETHODIMP CVTSReader::GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
    00130 {
    00131         if(!ppszFileName) return E_POINTER;
    00132
    00133         if(!(*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength()+1)*sizeof(WCHAR))))
    00134                 return E_OUTOFMEMORY;
    00135
    00136         wcscpy(*ppszFileName, m_fn);
    00137
    00138         return S_OK;
    00139 }
    00140
    00141 // CVTSStream
    00142
    00143 CVTSStream::CVTSStream() : m_off(0)
    00144 {
    00145         m_vob.Attach(new CVobFile());
    00146 }
    00147
    00148 CVTSStream::~CVTSStream()
    00149 {
    00150 }
    00151
    00152 bool CVTSStream::Load(const WCHAR* fnw)
    00153 {
    00154         CList<CString> sl;
    00155         return(m_vob && m_vob->Open(CString(fnw), sl) /*&& m_vob->IsDVD()*/);
    00156 }
    00157
    00158 HRESULT CVTSStream::SetPointer(LONGLONG llPos)
    00159 {
    00160         m_off = (int)(llPos&2047);
    00161         int lba = (int)(llPos/2048);
    00162
    00163         return lba == m_vob->Seek(lba) ? S_OK : S_FALSE;
    00164 }
    00165
    00166 HRESULT CVTSStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWORD pdwBytesRead)
    00167 {
    00168         CAutoLock lck(&m_csLock);
    00169
    00170         DWORD len = dwBytesToRead;
    00171         BYTE* ptr = pbBuffer;
    00172
    00173         while(len > 0)
    00174         {
    00175                 BYTE buff[2048];
    00176                 if(!m_vob->Read(buff))
    00177                         break;
    00178
    00179                 int size = min(2048 - m_off, min(len, 2048));
    00180
    00181                 memcpy(ptr, &buff[m_off], size);
    00182
    00183                 m_off = (m_off + size)&2047;
    00184
    00185                 if(m_off > 0)
    00186                         m_vob->Seek(m_vob->GetPosition()-1);
    00187
    00188                 ptr += size;
    00189                 len -= size;
    00190         }
    00191
    00192         if(pdwBytesRead)
    00193                 *pdwBytesRead = ptr - pbBuffer;
    00194
    00195         return S_OK;
    00196 }
    00197
    00198 LONGLONG CVTSStream::Size(LONGLONG* pSizeAvailable)
    00199 {
    00200         LONGLONG len = 2048i64*m_vob->GetLength();
    00201         if(pSizeAvailable) *pSizeAvailable = len;
    00202         return(len);
    00203 }
    00204
    00205 DWORD CVTSStream::Alignment()
    00206 {
    00207     return 1;
    00208 }
    00209
    00210 void CVTSStream::Lock()
    00211 {
    00212     m_csLock.Lock();
    00213 }
    00214
    00215 void CVTSStream::Unlock()
    00216 {
    00217     m_csLock.Unlock();
    00218 }
    00219