Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortetsuo55 <tetsuo55@users.sourceforge.net>2010-04-09 01:14:58 +0400
committertetsuo55 <tetsuo55@users.sourceforge.net>2010-04-09 01:14:58 +0400
commita9b7bf3fb3e1334d8defd05ca4cfae870b4912e5 (patch)
tree2dab453d94d5e003379a6cc895eceb84c80e23ec /src/filters/source
parentaafd49a91f7c2fa9c7103971c16fa6e1b29e8bfd (diff)
astyle formatting cleanup to make the sourcecode more accessible
switch used: astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren http://astyle.sourceforge.net/ git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@1783 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src/filters/source')
-rw-r--r--src/filters/source/BaseSource/BaseSource.cpp130
-rw-r--r--src/filters/source/BaseSource/BaseSource.h135
-rw-r--r--src/filters/source/BaseSource/stdafx.cpp8
-rw-r--r--src/filters/source/BaseSource/stdafx.h8
-rw-r--r--src/filters/source/D2VSource/D2VSource.cpp264
-rw-r--r--src/filters/source/D2VSource/D2VSource.h22
-rw-r--r--src/filters/source/D2VSource/MPEG2Dec.cpp7619
-rw-r--r--src/filters/source/D2VSource/MPEG2Dec.h418
-rw-r--r--src/filters/source/D2VSource/idctfpu.cpp714
-rw-r--r--src/filters/source/D2VSource/idctref.cpp618
-rw-r--r--src/filters/source/D2VSource/resource.h2
-rw-r--r--src/filters/source/DTSAC3Source/DTSAC3Source.cpp624
-rw-r--r--src/filters/source/DTSAC3Source/DTSAC3Source.h36
-rw-r--r--src/filters/source/DTSAC3Source/resource.h2
-rw-r--r--src/filters/source/DTSAC3Source/stdafx.cpp8
-rw-r--r--src/filters/source/DTSAC3Source/stdafx.h8
-rw-r--r--src/filters/source/FLICSource/FLICSource.cpp975
-rw-r--r--src/filters/source/FLICSource/FLICSource.h157
-rw-r--r--src/filters/source/FLICSource/resource.h2
-rw-r--r--src/filters/source/FLICSource/stdafx.cpp8
-rw-r--r--src/filters/source/FLICSource/stdafx.h8
-rw-r--r--src/filters/source/FlacSource/FlacSource.cpp325
-rw-r--r--src/filters/source/FlacSource/FlacSource.h47
-rw-r--r--src/filters/source/FlacSource/resource.h2
-rw-r--r--src/filters/source/FlacSource/stdafx.cpp8
-rw-r--r--src/filters/source/FlacSource/stdafx.h8
-rw-r--r--src/filters/source/ShoutcastSource/ShoutcastSource.cpp850
-rw-r--r--src/filters/source/ShoutcastSource/ShoutcastSource.h240
-rw-r--r--src/filters/source/ShoutcastSource/resource.h2
-rw-r--r--src/filters/source/ShoutcastSource/stdafx.cpp8
-rw-r--r--src/filters/source/ShoutcastSource/stdafx.h8
-rw-r--r--src/filters/source/SubtitleSource/SubtitleSource.cpp865
-rw-r--r--src/filters/source/SubtitleSource/SubtitleSource.h95
-rw-r--r--src/filters/source/SubtitleSource/resource.h2
-rw-r--r--src/filters/source/SubtitleSource/stdafx.cpp8
-rw-r--r--src/filters/source/SubtitleSource/stdafx.h8
36 files changed, 7193 insertions, 7049 deletions
diff --git a/src/filters/source/BaseSource/BaseSource.cpp b/src/filters/source/BaseSource/BaseSource.cpp
index 00ab0cc8e..b5cf0c708 100644
--- a/src/filters/source/BaseSource/BaseSource.cpp
+++ b/src/filters/source/BaseSource/BaseSource.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
@@ -31,68 +31,68 @@
// CBaseStream
//
-CBaseStream::CBaseStream(TCHAR* name, CSource* pParent, HRESULT* phr)
- : CSourceStream(name, phr, pParent, L"Output")
- , CSourceSeeking(name, (IPin*)this, phr, &m_cSharedState)
- , m_bDiscontinuity(FALSE), m_bFlushing(FALSE)
+CBaseStream::CBaseStream(TCHAR* name, CSource* pParent, HRESULT* phr)
+ : CSourceStream(name, phr, pParent, L"Output")
+ , CSourceSeeking(name, (IPin*)this, phr, &m_cSharedState)
+ , m_bDiscontinuity(FALSE), m_bFlushing(FALSE)
{
- CAutoLock cAutoLock(&m_cSharedState);
+ CAutoLock cAutoLock(&m_cSharedState);
- m_AvgTimePerFrame = 0;
- m_rtDuration = 0;
- m_rtStop = m_rtDuration;
+ m_AvgTimePerFrame = 0;
+ m_rtDuration = 0;
+ m_rtStop = m_rtDuration;
}
CBaseStream::~CBaseStream()
{
- CAutoLock cAutoLock(&m_cSharedState);
+ CAutoLock cAutoLock(&m_cSharedState);
}
STDMETHODIMP CBaseStream::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
CheckPointer(ppv, E_POINTER);
- return (riid == IID_IMediaSeeking) ? CSourceSeeking::NonDelegatingQueryInterface(riid, ppv)
- : CSourceStream::NonDelegatingQueryInterface(riid, ppv);
+ return (riid == IID_IMediaSeeking) ? CSourceSeeking::NonDelegatingQueryInterface(riid, ppv)
+ : CSourceStream::NonDelegatingQueryInterface(riid, ppv);
}
void CBaseStream::UpdateFromSeek()
{
- if(ThreadExists())
- {
- // next time around the loop, the worker thread will
- // pick up the position change.
- // We need to flush all the existing data - we must do that here
- // as our thread will probably be blocked in GetBuffer otherwise
-
- m_bFlushing = TRUE;
-
- DeliverBeginFlush();
- // make sure we have stopped pushing
- Stop();
- // complete the flush
- DeliverEndFlush();
+ if(ThreadExists())
+ {
+ // next time around the loop, the worker thread will
+ // pick up the position change.
+ // We need to flush all the existing data - we must do that here
+ // as our thread will probably be blocked in GetBuffer otherwise
+
+ m_bFlushing = TRUE;
+
+ DeliverBeginFlush();
+ // make sure we have stopped pushing
+ Stop();
+ // complete the flush
+ DeliverEndFlush();
m_bFlushing = FALSE;
- // restart
- Run();
- }
+ // restart
+ Run();
+ }
}
HRESULT CBaseStream::SetRate(double dRate)
{
- if(dRate <= 0)
- return E_INVALIDARG;
+ if(dRate <= 0)
+ return E_INVALIDARG;
- {
- CAutoLock lock(CSourceSeeking::m_pLock);
- m_dRateSeeking = dRate;
- }
+ {
+ CAutoLock lock(CSourceSeeking::m_pLock);
+ m_dRateSeeking = dRate;
+ }
- UpdateFromSeek();
+ UpdateFromSeek();
- return S_OK;
+ return S_OK;
}
HRESULT CBaseStream::OnThreadStartPlay()
@@ -105,8 +105,8 @@ HRESULT CBaseStream::ChangeStart()
{
{
CAutoLock lock(CSourceSeeking::m_pLock);
- m_rtSampleTime = 0;
- m_rtPosition = m_rtStart;
+ m_rtSampleTime = 0;
+ m_rtPosition = m_rtStart;
}
UpdateFromSeek();
@@ -119,7 +119,7 @@ HRESULT CBaseStream::ChangeStop()
{
CAutoLock lock(CSourceSeeking::m_pLock);
if(m_rtPosition < m_rtStop)
- return S_OK;
+ return S_OK;
}
// We're already past the new stop time -- better flush the graph.
@@ -140,49 +140,49 @@ HRESULT CBaseStream::OnThreadCreate()
HRESULT CBaseStream::FillBuffer(IMediaSample* pSample)
{
- HRESULT hr;
+ HRESULT hr;
- {
- CAutoLock cAutoLockShared(&m_cSharedState);
+ {
+ CAutoLock cAutoLockShared(&m_cSharedState);
if(m_rtPosition >= m_rtStop)
- return S_FALSE;
+ return S_FALSE;
- BYTE* pOut = NULL;
- if(FAILED(hr = pSample->GetPointer(&pOut)) || !pOut)
- return S_FALSE;
+ BYTE* pOut = NULL;
+ if(FAILED(hr = pSample->GetPointer(&pOut)) || !pOut)
+ return S_FALSE;
- int nFrame = m_rtPosition / m_AvgTimePerFrame; // (int)(1.0 * m_rtPosition / m_AvgTimePerFrame + 0.5);
+ int nFrame = m_rtPosition / m_AvgTimePerFrame; // (int)(1.0 * m_rtPosition / m_AvgTimePerFrame + 0.5);
- long len = pSample->GetSize();
+ long len = pSample->GetSize();
- hr = FillBuffer(pSample, nFrame, pOut, len);
- if(hr != S_OK) return hr;
+ hr = FillBuffer(pSample, nFrame, pOut, len);
+ if(hr != S_OK) return hr;
- pSample->SetActualDataLength(len);
+ pSample->SetActualDataLength(len);
- REFERENCE_TIME rtStart, rtStop;
+ REFERENCE_TIME rtStart, rtStop;
// The sample times are modified by the current rate.
rtStart = static_cast<REFERENCE_TIME>(m_rtSampleTime / m_dRateSeeking);
rtStop = rtStart + static_cast<int>(m_AvgTimePerFrame / m_dRateSeeking);
- pSample->SetTime(&rtStart, &rtStop);
+ pSample->SetTime(&rtStart, &rtStop);
m_rtSampleTime += m_AvgTimePerFrame;
m_rtPosition += m_AvgTimePerFrame;
- }
+ }
- pSample->SetSyncPoint(TRUE);
+ pSample->SetSyncPoint(TRUE);
- if(m_bDiscontinuity)
+ if(m_bDiscontinuity)
{
- pSample->SetDiscontinuity(TRUE);
- m_bDiscontinuity = FALSE;
- }
+ pSample->SetDiscontinuity(TRUE);
+ m_bDiscontinuity = FALSE;
+ }
- return S_OK;
+ return S_OK;
}
STDMETHODIMP CBaseStream::Notify(IBaseFilter* pSender, Quality q)
{
- return E_NOTIMPL;
+ return E_NOTIMPL;
}
diff --git a/src/filters/source/BaseSource/BaseSource.h b/src/filters/source/BaseSource/BaseSource.h
index 91e2ccdb8..07eed8751 100644
--- a/src/filters/source/BaseSource/BaseSource.h
+++ b/src/filters/source/BaseSource/BaseSource.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
@@ -25,99 +25,102 @@
template<class TStream>
class CBaseSource
- : public CSource
- , public IFileSourceFilter
- , public IAMFilterMiscFlags
+ : public CSource
+ , public IFileSourceFilter
+ , public IAMFilterMiscFlags
{
protected:
- CStringW m_fn;
+ CStringW m_fn;
public:
- CBaseSource(TCHAR* name, LPUNKNOWN lpunk, HRESULT* phr, const CLSID& clsid)
- : CSource(name, lpunk, clsid)
- {
- if(phr) *phr = S_OK;
- }
+ CBaseSource(TCHAR* name, LPUNKNOWN lpunk, HRESULT* phr, const CLSID& clsid)
+ : CSource(name, lpunk, clsid)
+ {
+ if(phr) *phr = S_OK;
+ }
- DECLARE_IUNKNOWN;
+ DECLARE_IUNKNOWN;
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv)
- {
- CheckPointer(ppv, E_POINTER);
+ {
+ CheckPointer(ppv, E_POINTER);
+
+ return
+ QI(IFileSourceFilter)
+ QI(IAMFilterMiscFlags)
+ __super::NonDelegatingQueryInterface(riid, ppv);
+ }
- return
- QI(IFileSourceFilter)
- QI(IAMFilterMiscFlags)
- __super::NonDelegatingQueryInterface(riid, ppv);
- }
+ // IFileSourceFilter
- // IFileSourceFilter
+ STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
+ {
+ // TODO: destroy any already existing pins and create new, now we are just going die nicely instead of doing it :)
+ if(GetPinCount() > 0)
+ return VFW_E_ALREADY_CONNECTED;
- STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
- {
- // TODO: destroy any already existing pins and create new, now we are just going die nicely instead of doing it :)
- if(GetPinCount() > 0)
- return VFW_E_ALREADY_CONNECTED;
+ HRESULT hr = S_OK;
+ if(!(DNew TStream(pszFileName, this, &hr)))
+ return E_OUTOFMEMORY;
- HRESULT hr = S_OK;
- if(!(DNew TStream(pszFileName, this, &hr)))
- return E_OUTOFMEMORY;
+ if(FAILED(hr))
+ return hr;
- if(FAILED(hr))
- return hr;
+ m_fn = pszFileName;
- m_fn = pszFileName;
+ return S_OK;
+ }
- return S_OK;
- }
+ STDMETHODIMP GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
+ {
+ size_t nCount;
+ if(!ppszFileName) return E_POINTER;
- STDMETHODIMP GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
- {
- size_t nCount;
- if(!ppszFileName) return E_POINTER;
-
- nCount = m_fn.GetLength()+1;
- if(!(*ppszFileName = (LPOLESTR)CoTaskMemAlloc(nCount*sizeof(WCHAR))))
- return E_OUTOFMEMORY;
+ nCount = m_fn.GetLength() + 1;
+ if(!(*ppszFileName = (LPOLESTR)CoTaskMemAlloc(nCount * sizeof(WCHAR))))
+ return E_OUTOFMEMORY;
- wcscpy_s(*ppszFileName, nCount, m_fn);
+ wcscpy_s(*ppszFileName, nCount, m_fn);
- return S_OK;
- }
+ return S_OK;
+ }
- // IAMFilterMiscFlags
+ // IAMFilterMiscFlags
- STDMETHODIMP_(ULONG) GetMiscFlags()
- {
- return AM_FILTER_MISC_FLAGS_IS_SOURCE;
- }
+ STDMETHODIMP_(ULONG) GetMiscFlags()
+ {
+ return AM_FILTER_MISC_FLAGS_IS_SOURCE;
+ }
};
-class CBaseStream
- : public CSourceStream
- , public CSourceSeeking
+class CBaseStream
+ : public CSourceStream
+ , public CSourceSeeking
{
protected:
- CCritSec m_cSharedState;
+ CCritSec m_cSharedState;
- REFERENCE_TIME m_AvgTimePerFrame;
- REFERENCE_TIME m_rtSampleTime, m_rtPosition;
+ REFERENCE_TIME m_AvgTimePerFrame;
+ REFERENCE_TIME m_rtSampleTime, m_rtPosition;
- BOOL m_bDiscontinuity, m_bFlushing;
+ BOOL m_bDiscontinuity, m_bFlushing;
- HRESULT OnThreadStartPlay();
- HRESULT OnThreadCreate();
+ HRESULT OnThreadStartPlay();
+ HRESULT OnThreadCreate();
private:
- void UpdateFromSeek();
- STDMETHODIMP SetRate(double dRate);
+ void UpdateFromSeek();
+ STDMETHODIMP SetRate(double dRate);
- HRESULT ChangeStart();
+ HRESULT ChangeStart();
HRESULT ChangeStop();
- HRESULT ChangeRate() {return S_OK;}
+ HRESULT ChangeRate()
+ {
+ return S_OK;
+ }
public:
CBaseStream(TCHAR* name, CSource* pParent, HRESULT* phr);
- virtual ~CBaseStream();
+ virtual ~CBaseStream();
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
@@ -125,5 +128,5 @@ public:
virtual HRESULT FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len /*in+out*/) = 0;
- STDMETHODIMP Notify(IBaseFilter* pSender, Quality q);
+ STDMETHODIMP Notify(IBaseFilter* pSender, Quality q);
};
diff --git a/src/filters/source/BaseSource/stdafx.cpp b/src/filters/source/BaseSource/stdafx.cpp
index 7407b6b89..8c08467b1 100644
--- a/src/filters/source/BaseSource/stdafx.cpp
+++ b/src/filters/source/BaseSource/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
diff --git a/src/filters/source/BaseSource/stdafx.h b/src/filters/source/BaseSource/stdafx.h
index 22cb54295..2bec11afc 100644
--- a/src/filters/source/BaseSource/stdafx.h
+++ b/src/filters/source/BaseSource/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
diff --git a/src/filters/source/D2VSource/D2VSource.cpp b/src/filters/source/D2VSource/D2VSource.cpp
index 6806e440f..088aa3fdd 100644
--- a/src/filters/source/D2VSource/D2VSource.cpp
+++ b/src/filters/source/D2VSource/D2VSource.cpp
@@ -1,19 +1,19 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
@@ -26,49 +26,49 @@
const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
{
- {&MEDIATYPE_Video, &MEDIASUBTYPE_YUY2}
+ {&MEDIATYPE_Video, &MEDIASUBTYPE_YUY2}
};
const AMOVIESETUP_PIN sudOpPin[] =
{
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
const AMOVIESETUP_FILTER sudFilter[] =
{
- {&__uuidof(CD2VSource), L"MPC - D2VSource", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
+ {&__uuidof(CD2VSource), L"MPC - D2VSource", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
};
CFactoryTemplate g_Templates[] =
{
- {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CD2VSource>, NULL, &sudFilter[0]}
+ {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CD2VSource>, NULL, &sudFilter[0]}
};
int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
- SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"),
- _T("0"), _T("0,18,,4456443241564950726F6A65637446696C65")); // "DVD2AVIProjectFile"
+ SetRegKeyValue(
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"),
+ _T("0"), _T("0,18,,4456443241564950726F6A65637446696C65")); // "DVD2AVIProjectFile"
- SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"),
- _T("Source Filter"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"));
+ SetRegKeyValue(
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"),
+ _T("Source Filter"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"));
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".d2v"),
- _T("Source Filter"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"));
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".d2v"),
+ _T("Source Filter"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"));
- return AMovieDllRegisterServer2(TRUE);
+ return AMovieDllRegisterServer2(TRUE);
}
STDAPI DllUnregisterServer()
{
- DeleteRegKey(_T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"));
- DeleteRegKey(_T("Media Type\\Extensions"), _T(".d2v"));
+ DeleteRegKey(_T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"));
+ DeleteRegKey(_T("Media Type\\Extensions"), _T(".d2v"));
- return AMovieDllRegisterServer2(FALSE);
+ return AMovieDllRegisterServer2(FALSE);
}
#include "../../FilterApp.h"
@@ -82,9 +82,9 @@ CFilterApp theApp;
//
CD2VSource::CD2VSource(LPUNKNOWN lpunk, HRESULT* phr)
- : CBaseSource<CD2VStream>(NAME("CD2VSource"), lpunk, phr, __uuidof(this))
+ : CBaseSource<CD2VStream>(NAME("CD2VSource"), lpunk, phr, __uuidof(this))
{
- if(phr) *phr = S_OK;
+ if(phr) *phr = S_OK;
}
CD2VSource::~CD2VSource()
@@ -95,40 +95,40 @@ CD2VSource::~CD2VSource()
// CD2VStream
//
-CD2VStream::CD2VStream(const WCHAR* fn, CSource* pParent, HRESULT* phr)
- : CBaseStream(NAME("D2VSourceStream"), pParent, phr)
- , m_pFrameBuffer(NULL)
+CD2VStream::CD2VStream(const WCHAR* fn, CSource* pParent, HRESULT* phr)
+ : CBaseStream(NAME("D2VSourceStream"), pParent, phr)
+ , m_pFrameBuffer(NULL)
{
- CAutoLock cAutoLock(&m_cSharedState);
-
- m_pDecoder.Attach(DNew CMPEG2Dec());
- if(!m_pDecoder)
- {
- if(phr) *phr = E_OUTOFMEMORY;
- return;
- }
-
- if(!m_pDecoder->Open(CString(fn), CMPEG2Dec::YUY2))
- {
- if(phr) *phr = E_FAIL;
- return;
- }
-
- if(!m_pFrameBuffer.Allocate(m_pDecoder->Clip_Width*m_pDecoder->Clip_Height*4))
- {
- if(phr) *phr = E_OUTOFMEMORY;
- return;
- }
-
- m_AvgTimePerFrame = 10000000000i64/m_pDecoder->VF_FrameRate;
- m_rtDuration = m_rtStop = m_AvgTimePerFrame*m_pDecoder->VF_FrameLimit;
-
- if(phr) *phr = m_rtDuration > 0 ? S_OK : E_FAIL;
+ CAutoLock cAutoLock(&m_cSharedState);
+
+ m_pDecoder.Attach(DNew CMPEG2Dec());
+ if(!m_pDecoder)
+ {
+ if(phr) *phr = E_OUTOFMEMORY;
+ return;
+ }
+
+ if(!m_pDecoder->Open(CString(fn), CMPEG2Dec::YUY2))
+ {
+ if(phr) *phr = E_FAIL;
+ return;
+ }
+
+ if(!m_pFrameBuffer.Allocate(m_pDecoder->Clip_Width * m_pDecoder->Clip_Height * 4))
+ {
+ if(phr) *phr = E_OUTOFMEMORY;
+ return;
+ }
+
+ m_AvgTimePerFrame = 10000000000i64 / m_pDecoder->VF_FrameRate;
+ m_rtDuration = m_rtStop = m_AvgTimePerFrame * m_pDecoder->VF_FrameLimit;
+
+ if(phr) *phr = m_rtDuration > 0 ? S_OK : E_FAIL;
}
CD2VStream::~CD2VStream()
{
- CAutoLock cAutoLock(&m_cSharedState);
+ CAutoLock cAutoLock(&m_cSharedState);
}
HRESULT CD2VStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties)
@@ -140,12 +140,12 @@ HRESULT CD2VStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES
HRESULT hr = NOERROR;
- int w, h, bpp;
- if(!GetDim(w, h, bpp))
- return E_FAIL;
+ int w, h, bpp;
+ if(!GetDim(w, h, bpp))
+ return E_FAIL;
- pProperties->cBuffers = 1;
- pProperties->cbBuffer = w*h*bpp>>3;
+ pProperties->cBuffers = 1;
+ pProperties->cbBuffer = w * h * bpp >> 3;
ALLOCATOR_PROPERTIES Actual;
if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
@@ -158,41 +158,41 @@ HRESULT CD2VStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES
HRESULT CD2VStream::FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len)
{
- if(!m_pDecoder)
- return S_FALSE;
+ if(!m_pDecoder)
+ return S_FALSE;
- AM_MEDIA_TYPE* pmt;
- if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt)
- {
- CMediaType mt(*pmt);
- SetMediaType(&mt);
+ AM_MEDIA_TYPE* pmt;
+ if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt)
+ {
+ CMediaType mt(*pmt);
+ SetMediaType(&mt);
- DeleteMediaType(pmt);
- }
+ DeleteMediaType(pmt);
+ }
- int w, h, bpp;
- if(!GetDim(w, h, bpp))
- return S_FALSE;
+ int w, h, bpp;
+ if(!GetDim(w, h, bpp))
+ return S_FALSE;
- BYTE* pIn = m_pFrameBuffer;
+ BYTE* pIn = m_pFrameBuffer;
- int pitchIn, pitchOut = 0;
+ int pitchIn, pitchOut = 0;
- pitchIn = m_pDecoder->Clip_Width*bpp>>3;
- pitchOut = w*bpp>>3;
+ pitchIn = m_pDecoder->Clip_Width * bpp >> 3;
+ pitchOut = w * bpp >> 3;
- m_pDecoder->Decode(pIn, (unsigned long)(nFrame), pitchIn);
+ m_pDecoder->Decode(pIn, (unsigned long)(nFrame), pitchIn);
- for(int y = 0, p = min(pitchIn, pitchOut);
- y < h;
- y++, pIn += pitchIn, pOut += pitchOut)
- {
- memcpy(pOut, pIn, p);
- }
+ for(int y = 0, p = min(pitchIn, pitchOut);
+ y < h;
+ y++, pIn += pitchIn, pOut += pitchOut)
+ {
+ memcpy(pOut, pIn, p);
+ }
- len = pitchOut*h;
+ len = pitchOut * h;
- return S_OK;
+ return S_OK;
}
HRESULT CD2VStream::GetMediaType(int iPosition, CMediaType* pmt)
@@ -207,77 +207,77 @@ HRESULT CD2VStream::GetMediaType(int iPosition, CMediaType* pmt)
pmt->SetFormatType(&FORMAT_VideoInfo);
pmt->SetTemporalCompression(FALSE);
- VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
- memset(vih, 0, sizeof(VIDEOINFOHEADER));
- vih->AvgTimePerFrame = m_AvgTimePerFrame;
- vih->bmiHeader.biSize = sizeof(vih->bmiHeader);
- vih->bmiHeader.biWidth = m_pDecoder->Clip_Width;
- vih->bmiHeader.biHeight = m_pDecoder->Clip_Height;
- vih->bmiHeader.biPlanes = 1;
- vih->bmiHeader.biBitCount = 16;
- vih->bmiHeader.biCompression = '2YUY';
- vih->bmiHeader.biSizeImage = vih->bmiHeader.biWidth*abs(vih->bmiHeader.biHeight)*vih->bmiHeader.biBitCount>>3;
+ VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
+ memset(vih, 0, sizeof(VIDEOINFOHEADER));
+ vih->AvgTimePerFrame = m_AvgTimePerFrame;
+ vih->bmiHeader.biSize = sizeof(vih->bmiHeader);
+ vih->bmiHeader.biWidth = m_pDecoder->Clip_Width;
+ vih->bmiHeader.biHeight = m_pDecoder->Clip_Height;
+ vih->bmiHeader.biPlanes = 1;
+ vih->bmiHeader.biBitCount = 16;
+ vih->bmiHeader.biCompression = '2YUY';
+ vih->bmiHeader.biSizeImage = vih->bmiHeader.biWidth * abs(vih->bmiHeader.biHeight) * vih->bmiHeader.biBitCount >> 3;
- pmt->SetSampleSize(vih->bmiHeader.biSizeImage);
+ pmt->SetSampleSize(vih->bmiHeader.biSizeImage);
return NOERROR;
}
HRESULT CD2VStream::SetMediaType(const CMediaType* pmt)
{
- if(m_pDecoder)
- {
- if(pmt->subtype == MEDIASUBTYPE_YUY2)
- m_pDecoder->m_dstFormat = CMPEG2Dec::YUY2;
- else
- return E_FAIL;
- }
-
- return CSourceStream::SetMediaType(pmt);
+ if(m_pDecoder)
+ {
+ if(pmt->subtype == MEDIASUBTYPE_YUY2)
+ m_pDecoder->m_dstFormat = CMPEG2Dec::YUY2;
+ else
+ return E_FAIL;
+ }
+
+ return CSourceStream::SetMediaType(pmt);
}
HRESULT CD2VStream::CheckMediaType(const CMediaType* pmt)
{
- return pmt->majortype == MEDIATYPE_Video
- && pmt->subtype == MEDIASUBTYPE_YUY2
- && pmt->formattype == FORMAT_VideoInfo
- ? S_OK
- : E_INVALIDARG;
+ return pmt->majortype == MEDIATYPE_Video
+ && pmt->subtype == MEDIASUBTYPE_YUY2
+ && pmt->formattype == FORMAT_VideoInfo
+ ? S_OK
+ : E_INVALIDARG;
}
STDMETHODIMP CD2VStream::Notify(IBaseFilter* pSender, Quality q)
{
- if(q.Late > 0 && q.Late < 100000000)
- {
- CAutoLock cAutoLockShared(&m_cSharedState);
+ if(q.Late > 0 && q.Late < 100000000)
+ {
+ CAutoLock cAutoLockShared(&m_cSharedState);
- m_rtSampleTime += (q.Late/m_AvgTimePerFrame)*m_AvgTimePerFrame;
- m_rtPosition += (q.Late/m_AvgTimePerFrame)*m_AvgTimePerFrame;
- }
+ m_rtSampleTime += (q.Late / m_AvgTimePerFrame) * m_AvgTimePerFrame;
+ m_rtPosition += (q.Late / m_AvgTimePerFrame) * m_AvgTimePerFrame;
+ }
- return S_OK;
+ return S_OK;
}
//
bool CD2VStream::GetDim(int& w, int& h, int& bpp)
{
- if(m_mt.formattype == FORMAT_VideoInfo)
- {
- w = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biWidth;
- h = abs(((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biHeight);
- bpp = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biBitCount;
- }
- else if(m_mt.formattype == FORMAT_VideoInfo2)
- {
- w = ((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biWidth;
- h = abs(((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biHeight);
- bpp = ((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biBitCount;
- }
- else
- {
- return(false);
- }
-
- return(true);
+ if(m_mt.formattype == FORMAT_VideoInfo)
+ {
+ w = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biWidth;
+ h = abs(((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biHeight);
+ bpp = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biBitCount;
+ }
+ else if(m_mt.formattype == FORMAT_VideoInfo2)
+ {
+ w = ((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biWidth;
+ h = abs(((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biHeight);
+ bpp = ((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biBitCount;
+ }
+ else
+ {
+ return(false);
+ }
+
+ return(true);
}
diff --git a/src/filters/source/D2VSource/D2VSource.h b/src/filters/source/D2VSource/D2VSource.h
index bf2e18f9a..ac0bddc2d 100644
--- a/src/filters/source/D2VSource/D2VSource.h
+++ b/src/filters/source/D2VSource/D2VSource.h
@@ -1,19 +1,19 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
@@ -27,8 +27,8 @@ class CD2VStream;
class CD2VSource : public CBaseSource<CD2VStream>
{
public:
- CD2VSource(LPUNKNOWN lpunk, HRESULT* phr);
- virtual ~CD2VSource();
+ CD2VSource(LPUNKNOWN lpunk, HRESULT* phr);
+ virtual ~CD2VSource();
};
class CMPEG2Dec;
@@ -36,14 +36,14 @@ class CMPEG2Dec;
class CD2VStream : public CBaseStream
{
private:
- CAutoPtr<CMPEG2Dec> m_pDecoder;
- CAutoVectorPtr<BYTE> m_pFrameBuffer;
+ CAutoPtr<CMPEG2Dec> m_pDecoder;
+ CAutoVectorPtr<BYTE> m_pFrameBuffer;
- bool GetDim(int& w, int& h, int& bpp);
+ bool GetDim(int& w, int& h, int& bpp);
public:
CD2VStream(const WCHAR* fn, CSource* pParent, HRESULT* phr);
- virtual ~CD2VStream();
+ virtual ~CD2VStream();
HRESULT FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len /*in+out*/);
@@ -52,5 +52,5 @@ public:
HRESULT GetMediaType(int iPosition, CMediaType* pmt);
HRESULT SetMediaType(const CMediaType* pmt);
- STDMETHODIMP Notify(IBaseFilter* pSender, Quality q);
+ STDMETHODIMP Notify(IBaseFilter* pSender, Quality q);
};
diff --git a/src/filters/source/D2VSource/MPEG2Dec.cpp b/src/filters/source/D2VSource/MPEG2Dec.cpp
index 4be664c00..c8c4758ed 100644
--- a/src/filters/source/D2VSource/MPEG2Dec.cpp
+++ b/src/filters/source/D2VSource/MPEG2Dec.cpp
@@ -3,39 +3,40 @@
int testint;
-struct CPU {
- BOOL mmx;
- BOOL _3dnow;
- BOOL ssemmx;
- BOOL ssefpu;
+struct CPU
+{
+ BOOL mmx;
+ BOOL _3dnow;
+ BOOL ssemmx;
+ BOOL ssefpu;
} cpu;
void CheckCPU()
{
- __asm
- {
- mov eax, 1
- cpuid
- test edx, 0x00800000 // STD MMX
- jz TEST_SSE
- mov [cpu.mmx], 1
-TEST_SSE:
- test edx, 0x02000000 // STD SSE
- jz TEST_3DNOW
- mov [cpu.ssemmx], 1
- mov [cpu.ssefpu], 1
-TEST_3DNOW:
- mov eax, 0x80000001
- cpuid
- test edx, 0x80000000 // 3D NOW
- jz TEST_SSEMMX
- mov [cpu._3dnow], 1
-TEST_SSEMMX:
- test edx, 0x00400000 // SSE MMX
- jz TEST_END
- mov [cpu.ssemmx], 1
-TEST_END:
- }
+ __asm
+ {
+ mov eax, 1
+ cpuid
+ test edx, 0x00800000 // STD MMX
+ jz TEST_SSE
+ mov [cpu.mmx], 1
+ TEST_SSE:
+ test edx, 0x02000000 // STD SSE
+ jz TEST_3DNOW
+ mov [cpu.ssemmx], 1
+ mov [cpu.ssefpu], 1
+ TEST_3DNOW:
+ mov eax, 0x80000001
+ cpuid
+ test edx, 0x80000000 // 3D NOW
+ jz TEST_SSEMMX
+ mov [cpu._3dnow], 1
+ TEST_SSEMMX:
+ test edx, 0x00400000 // SSE MMX
+ jz TEST_END
+ mov [cpu.ssemmx], 1
+ TEST_END:
+ }
}
#pragma warning(disable:4799) // no EMMS
@@ -51,168 +52,170 @@ extern void REF_IDCT(short *block);
/* default intra quantization matrix */
static unsigned char default_intra_quantizer_matrix[64] =
{
- 8, 16, 19, 22, 26, 27, 29, 34,
- 16, 16, 22, 24, 27, 29, 34, 37,
- 19, 22, 26, 27, 29, 34, 34, 38,
- 22, 22, 26, 27, 29, 34, 37, 40,
- 22, 26, 27, 29, 32, 35, 40, 48,
- 26, 27, 29, 32, 35, 40, 48, 58,
- 26, 27, 29, 34, 38, 46, 56, 69,
- 27, 29, 35, 38, 46, 56, 69, 83
+ 8, 16, 19, 22, 26, 27, 29, 34,
+ 16, 16, 22, 24, 27, 29, 34, 37,
+ 19, 22, 26, 27, 29, 34, 34, 38,
+ 22, 22, 26, 27, 29, 34, 37, 40,
+ 22, 26, 27, 29, 32, 35, 40, 48,
+ 26, 27, 29, 32, 35, 40, 48, 58,
+ 26, 27, 29, 34, 38, 46, 56, 69,
+ 27, 29, 35, 38, 46, 56, 69, 83
};
/* zig-zag and alternate scan patterns */
static unsigned char scan[2][64] =
{
- { /* Zig-Zag scan pattern */
- 0, 1, 8, 16, 9, 2, 3, 10,
- 17, 24, 32, 25, 18, 11, 4, 5,
- 12, 19, 26, 33, 40, 48, 41, 34,
- 27, 20, 13, 6, 7, 14, 21, 28,
- 35, 42, 49, 56, 57, 50, 43, 36,
- 29, 22, 15, 23, 30, 37, 44, 51,
- 58, 59, 52, 45, 38, 31, 39, 46,
- 53, 60, 61, 54, 47, 55, 62, 63
- }
- ,
- { /* Alternate scan pattern */
- 0, 8, 16, 24, 1, 9, 2, 10,
- 17, 25, 32, 40, 48, 56, 57, 49,
- 41, 33, 26, 18, 3, 11, 4, 12,
- 19, 27, 34, 42, 50, 58, 35, 43,
- 51, 59, 20, 28, 5, 13, 6, 14,
- 21, 29, 36, 44, 52, 60, 37, 45,
- 53, 61, 22, 30, 7, 15, 23, 31,
- 38, 46, 54, 62, 39, 47, 55, 63
- }
+ { /* Zig-Zag scan pattern */
+ 0, 1, 8, 16, 9, 2, 3, 10,
+ 17, 24, 32, 25, 18, 11, 4, 5,
+ 12, 19, 26, 33, 40, 48, 41, 34,
+ 27, 20, 13, 6, 7, 14, 21, 28,
+ 35, 42, 49, 56, 57, 50, 43, 36,
+ 29, 22, 15, 23, 30, 37, 44, 51,
+ 58, 59, 52, 45, 38, 31, 39, 46,
+ 53, 60, 61, 54, 47, 55, 62, 63
+ }
+ ,
+ { /* Alternate scan pattern */
+ 0, 8, 16, 24, 1, 9, 2, 10,
+ 17, 25, 32, 40, 48, 56, 57, 49,
+ 41, 33, 26, 18, 3, 11, 4, 12,
+ 19, 27, 34, 42, 50, 58, 35, 43,
+ 51, 59, 20, 28, 5, 13, 6, 14,
+ 21, 29, 36, 44, 52, 60, 37, 45,
+ 53, 61, 22, 30, 7, 15, 23, 31,
+ 38, 46, 54, 62, 39, 47, 55, 63
+ }
};
/* non-linear quantization coefficient table */
static unsigned char Non_Linear_quantizer_scale[32] =
{
- 0, 1, 2, 3, 4, 5, 6, 7,
- 8, 10, 12, 14, 16, 18, 20, 22,
- 24, 28, 32, 36, 40, 44, 48, 52,
- 56, 64, 72, 80, 88, 96, 104, 112
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 10, 12, 14, 16, 18, 20, 22,
+ 24, 28, 32, 36, 40, 44, 48, 52,
+ 56, 64, 72, 80, 88, 96, 104, 112
};
#define ERROR_VALUE (-1)
-typedef struct {
- char run, level, len;
+typedef struct
+{
+ char run, level, len;
} DCTtab;
-typedef struct {
- char val, len;
+typedef struct
+{
+ char val, len;
} VLCtab;
/* Table B-10, motion_code, codes 0001 ... 01xx */
static VLCtab MVtab0[8] =
{
- {ERROR_VALUE,0}, {3,3}, {2,2}, {2,2}, {1,1}, {1,1}, {1,1}, {1,1}
+ {ERROR_VALUE, 0}, {3, 3}, {2, 2}, {2, 2}, {1, 1}, {1, 1}, {1, 1}, {1, 1}
};
/* Table B-10, motion_code, codes 0000011 ... 000011x */
static VLCtab MVtab1[8] =
{
- {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0}, {7,6}, {6,6}, {5,6}, {4,5}, {4,5}
+ {ERROR_VALUE, 0}, {ERROR_VALUE, 0}, {ERROR_VALUE, 0}, {7, 6}, {6, 6}, {5, 6}, {4, 5}, {4, 5}
};
/* Table B-10, motion_code, codes 0000001100 ... 000001011x */
static VLCtab MVtab2[12] =
{
- {16,9}, {15,9}, {14,9}, {13,9},
- {12,9}, {11,9}, {10,8}, {10,8},
- {9,8}, {9,8}, {8,8}, {8,8}
+ {16, 9}, {15, 9}, {14, 9}, {13, 9},
+ {12, 9}, {11, 9}, {10, 8}, {10, 8},
+ {9, 8}, {9, 8}, {8, 8}, {8, 8}
};
/* Table B-9, coded_block_pattern, codes 01000 ... 111xx */
static VLCtab CBPtab0[32] =
{
- {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0},
- {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0},
- {62,5}, {2,5}, {61,5}, {1,5}, {56,5}, {52,5}, {44,5}, {28,5},
- {40,5}, {20,5}, {48,5}, {12,5}, {32,4}, {32,4}, {16,4}, {16,4},
- {8,4}, {8,4}, {4,4}, {4,4}, {60,3}, {60,3}, {60,3}, {60,3}
+ {ERROR_VALUE, 0}, {ERROR_VALUE, 0}, {ERROR_VALUE, 0}, {ERROR_VALUE, 0},
+ {ERROR_VALUE, 0}, {ERROR_VALUE, 0}, {ERROR_VALUE, 0}, {ERROR_VALUE, 0},
+ {62, 5}, {2, 5}, {61, 5}, {1, 5}, {56, 5}, {52, 5}, {44, 5}, {28, 5},
+ {40, 5}, {20, 5}, {48, 5}, {12, 5}, {32, 4}, {32, 4}, {16, 4}, {16, 4},
+ {8, 4}, {8, 4}, {4, 4}, {4, 4}, {60, 3}, {60, 3}, {60, 3}, {60, 3}
};
/* Table B-9, coded_block_pattern, codes 00000100 ... 001111xx */
static VLCtab CBPtab1[64] =
{
- {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0},
- {58,8}, {54,8}, {46,8}, {30,8},
- {57,8}, {53,8}, {45,8}, {29,8}, {38,8}, {26,8}, {37,8}, {25,8},
- {43,8}, {23,8}, {51,8}, {15,8}, {42,8}, {22,8}, {50,8}, {14,8},
- {41,8}, {21,8}, {49,8}, {13,8}, {35,8}, {19,8}, {11,8}, {7,8},
- {34,7}, {34,7}, {18,7}, {18,7}, {10,7}, {10,7}, {6,7}, {6,7},
- {33,7}, {33,7}, {17,7}, {17,7}, {9,7}, {9,7}, {5,7}, {5,7},
- {63,6}, {63,6}, {63,6}, {63,6}, {3,6}, {3,6}, {3,6}, {3,6},
- {36,6}, {36,6}, {36,6}, {36,6}, {24,6}, {24,6}, {24,6}, {24,6}
+ {ERROR_VALUE, 0}, {ERROR_VALUE, 0}, {ERROR_VALUE, 0}, {ERROR_VALUE, 0},
+ {58, 8}, {54, 8}, {46, 8}, {30, 8},
+ {57, 8}, {53, 8}, {45, 8}, {29, 8}, {38, 8}, {26, 8}, {37, 8}, {25, 8},
+ {43, 8}, {23, 8}, {51, 8}, {15, 8}, {42, 8}, {22, 8}, {50, 8}, {14, 8},
+ {41, 8}, {21, 8}, {49, 8}, {13, 8}, {35, 8}, {19, 8}, {11, 8}, {7, 8},
+ {34, 7}, {34, 7}, {18, 7}, {18, 7}, {10, 7}, {10, 7}, {6, 7}, {6, 7},
+ {33, 7}, {33, 7}, {17, 7}, {17, 7}, {9, 7}, {9, 7}, {5, 7}, {5, 7},
+ {63, 6}, {63, 6}, {63, 6}, {63, 6}, {3, 6}, {3, 6}, {3, 6}, {3, 6},
+ {36, 6}, {36, 6}, {36, 6}, {36, 6}, {24, 6}, {24, 6}, {24, 6}, {24, 6}
};
/* Table B-9, coded_block_pattern, codes 000000001 ... 000000111 */
static VLCtab CBPtab2[8] =
{
- {ERROR_VALUE,0}, {0,9}, {39,9}, {27,9}, {59,9}, {55,9}, {47,9}, {31,9}
+ {ERROR_VALUE, 0}, {0, 9}, {39, 9}, {27, 9}, {59, 9}, {55, 9}, {47, 9}, {31, 9}
};
/* Table B-1, macroblock_address_increment, codes 00010 ... 011xx */
static VLCtab MBAtab1[16] =
{
- {ERROR_VALUE,0}, {ERROR_VALUE,0}, {7,5}, {6,5}, {5,4}, {5,4}, {4,4},
- {4,4}, {3,3}, {3,3}, {3,3}, {3,3}, {2,3}, {2,3}, {2,3}, {2,3}
+ {ERROR_VALUE, 0}, {ERROR_VALUE, 0}, {7, 5}, {6, 5}, {5, 4}, {5, 4}, {4, 4},
+ {4, 4}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}
};
/* Table B-1, macroblock_address_increment, codes 00000011000 ... 0000111xxxx */
static VLCtab MBAtab2[104] =
{
- {33,11}, {32,11}, {31,11}, {30,11}, {29,11}, {28,11}, {27,11}, {26,11},
- {25,11}, {24,11}, {23,11}, {22,11}, {21,10}, {21,10}, {20,10}, {20,10},
- {19,10}, {19,10}, {18,10}, {18,10}, {17,10}, {17,10}, {16,10}, {16,10},
- {15,8}, {15,8}, {15,8}, {15,8}, {15,8}, {15,8}, {15,8}, {15,8},
- {14,8}, {14,8}, {14,8}, {14,8}, {14,8}, {14,8}, {14,8}, {14,8},
- {13,8}, {13,8}, {13,8}, {13,8}, {13,8}, {13,8}, {13,8}, {13,8},
- {12,8}, {12,8}, {12,8}, {12,8}, {12,8}, {12,8}, {12,8}, {12,8},
- {11,8}, {11,8}, {11,8}, {11,8}, {11,8}, {11,8}, {11,8}, {11,8},
- {10,8}, {10,8}, {10,8}, {10,8}, {10,8}, {10,8}, {10,8}, {10,8},
- {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7},
- {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7},
- {8,7}, {8,7}, {8,7}, {8,7}, {8,7}, {8,7}, {8,7}, {8,7},
- {8,7}, {8,7}, {8,7}, {8,7}, {8,7}, {8,7}, {8,7}, {8,7}
+ {33, 11}, {32, 11}, {31, 11}, {30, 11}, {29, 11}, {28, 11}, {27, 11}, {26, 11},
+ {25, 11}, {24, 11}, {23, 11}, {22, 11}, {21, 10}, {21, 10}, {20, 10}, {20, 10},
+ {19, 10}, {19, 10}, {18, 10}, {18, 10}, {17, 10}, {17, 10}, {16, 10}, {16, 10},
+ {15, 8}, {15, 8}, {15, 8}, {15, 8}, {15, 8}, {15, 8}, {15, 8}, {15, 8},
+ {14, 8}, {14, 8}, {14, 8}, {14, 8}, {14, 8}, {14, 8}, {14, 8}, {14, 8},
+ {13, 8}, {13, 8}, {13, 8}, {13, 8}, {13, 8}, {13, 8}, {13, 8}, {13, 8},
+ {12, 8}, {12, 8}, {12, 8}, {12, 8}, {12, 8}, {12, 8}, {12, 8}, {12, 8},
+ {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8},
+ {10, 8}, {10, 8}, {10, 8}, {10, 8}, {10, 8}, {10, 8}, {10, 8}, {10, 8},
+ {9, 7}, {9, 7}, {9, 7}, {9, 7}, {9, 7}, {9, 7}, {9, 7}, {9, 7},
+ {9, 7}, {9, 7}, {9, 7}, {9, 7}, {9, 7}, {9, 7}, {9, 7}, {9, 7},
+ {8, 7}, {8, 7}, {8, 7}, {8, 7}, {8, 7}, {8, 7}, {8, 7}, {8, 7},
+ {8, 7}, {8, 7}, {8, 7}, {8, 7}, {8, 7}, {8, 7}, {8, 7}, {8, 7}
};
/* Table B-12, dct_dc_size_luminance, codes 00xxx ... 11110 */
static VLCtab DClumtab0[32] =
{
- {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
- {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
- {0, 3}, {0, 3}, {0, 3}, {0, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
- {4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5}, {ERROR_VALUE, 0}
+ {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
+ {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
+ {0, 3}, {0, 3}, {0, 3}, {0, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
+ {4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5}, {ERROR_VALUE, 0}
};
/* Table B-12, dct_dc_size_luminance, codes 111110xxx ... 111111111 */
static VLCtab DClumtab1[16] =
{
- {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6},
- {8, 7}, {8, 7}, {8, 7}, {8, 7}, {9, 8}, {9, 8}, {10,9}, {11,9}
+ {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6},
+ {8, 7}, {8, 7}, {8, 7}, {8, 7}, {9, 8}, {9, 8}, {10, 9}, {11, 9}
};
/* Table B-13, dct_dc_size_chrominance, codes 00xxx ... 11110 */
static VLCtab DCchromtab0[32] =
{
- {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
- {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
- {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
- {3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 4}, {4, 4}, {5, 5}, {ERROR_VALUE, 0}
+ {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
+ {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
+ {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
+ {3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 4}, {4, 4}, {5, 5}, {ERROR_VALUE, 0}
};
/* Table B-13, dct_dc_size_chrominance, codes 111110xxxx ... 1111111111 */
static VLCtab DCchromtab1[32] =
{
- {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
- {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
- {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7},
- {8, 8}, {8, 8}, {8, 8}, {8, 8}, {9, 9}, {9, 9}, {10,10}, {11,10}
+ {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
+ {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6},
+ {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7},
+ {8, 8}, {8, 8}, {8, 8}, {8, 8}, {9, 9}, {9, 9}, {10, 10}, {11, 10}
};
/* Table B-14, DCT coefficients table zero,
@@ -220,9 +223,9 @@ static VLCtab DCchromtab1[32] =
*/
static DCTtab DCTtabfirst[12] =
{
- {0,2,4}, {2,1,4}, {1,1,3}, {1,1,3},
- {0,1,1}, {0,1,1}, {0,1,1}, {0,1,1},
- {0,1,1}, {0,1,1}, {0,1,1}, {0,1,1}
+ {0, 2, 4}, {2, 1, 4}, {1, 1, 3}, {1, 1, 3},
+ {0, 1, 1}, {0, 1, 1}, {0, 1, 1}, {0, 1, 1},
+ {0, 1, 1}, {0, 1, 1}, {0, 1, 1}, {0, 1, 1}
};
/* Table B-14, DCT coefficients table zero,
@@ -230,9 +233,9 @@ static DCTtab DCTtabfirst[12] =
*/
static DCTtab DCTtabnext[12] =
{
- {0,2,4}, {2,1,4}, {1,1,3}, {1,1,3},
- {64,0,2}, {64,0,2}, {64,0,2}, {64,0,2}, /* EOB */
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}
+ {0, 2, 4}, {2, 1, 4}, {1, 1, 3}, {1, 1, 3},
+ {64, 0, 2}, {64, 0, 2}, {64, 0, 2}, {64, 0, 2}, /* EOB */
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2}
};
/* Table B-14, DCT coefficients table zero,
@@ -240,21 +243,21 @@ static DCTtab DCTtabnext[12] =
*/
static DCTtab DCTtab0[60] =
{
- {65,0,6}, {65,0,6}, {65,0,6}, {65,0,6}, /* Escape */
- {2,2,7}, {2,2,7}, {9,1,7}, {9,1,7},
- {0,4,7}, {0,4,7}, {8,1,7}, {8,1,7},
- {7,1,6}, {7,1,6}, {7,1,6}, {7,1,6},
- {6,1,6}, {6,1,6}, {6,1,6}, {6,1,6},
- {1,2,6}, {1,2,6}, {1,2,6}, {1,2,6},
- {5,1,6}, {5,1,6}, {5,1,6}, {5,1,6},
- {13,1,8}, {0,6,8}, {12,1,8}, {11,1,8},
- {3,2,8}, {1,3,8}, {0,5,8}, {10,1,8},
- {0,3,5}, {0,3,5}, {0,3,5}, {0,3,5},
- {0,3,5}, {0,3,5}, {0,3,5}, {0,3,5},
- {4,1,5}, {4,1,5}, {4,1,5}, {4,1,5},
- {4,1,5}, {4,1,5}, {4,1,5}, {4,1,5},
- {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5},
- {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5}
+ {65, 0, 6}, {65, 0, 6}, {65, 0, 6}, {65, 0, 6}, /* Escape */
+ {2, 2, 7}, {2, 2, 7}, {9, 1, 7}, {9, 1, 7},
+ {0, 4, 7}, {0, 4, 7}, {8, 1, 7}, {8, 1, 7},
+ {7, 1, 6}, {7, 1, 6}, {7, 1, 6}, {7, 1, 6},
+ {6, 1, 6}, {6, 1, 6}, {6, 1, 6}, {6, 1, 6},
+ {1, 2, 6}, {1, 2, 6}, {1, 2, 6}, {1, 2, 6},
+ {5, 1, 6}, {5, 1, 6}, {5, 1, 6}, {5, 1, 6},
+ {13, 1, 8}, {0, 6, 8}, {12, 1, 8}, {11, 1, 8},
+ {3, 2, 8}, {1, 3, 8}, {0, 5, 8}, {10, 1, 8},
+ {0, 3, 5}, {0, 3, 5}, {0, 3, 5}, {0, 3, 5},
+ {0, 3, 5}, {0, 3, 5}, {0, 3, 5}, {0, 3, 5},
+ {4, 1, 5}, {4, 1, 5}, {4, 1, 5}, {4, 1, 5},
+ {4, 1, 5}, {4, 1, 5}, {4, 1, 5}, {4, 1, 5},
+ {3, 1, 5}, {3, 1, 5}, {3, 1, 5}, {3, 1, 5},
+ {3, 1, 5}, {3, 1, 5}, {3, 1, 5}, {3, 1, 5}
};
/* Table B-15, DCT coefficients table one,
@@ -262,69 +265,69 @@ static DCTtab DCTtab0[60] =
*/
static DCTtab DCTtab0a[252] =
{
- {65,0,6}, {65,0,6}, {65,0,6}, {65,0,6}, /* Escape */
- {7,1,7}, {7,1,7}, {8,1,7}, {8,1,7},
- {6,1,7}, {6,1,7}, {2,2,7}, {2,2,7},
- {0,7,6}, {0,7,6}, {0,7,6}, {0,7,6},
- {0,6,6}, {0,6,6}, {0,6,6}, {0,6,6},
- {4,1,6}, {4,1,6}, {4,1,6}, {4,1,6},
- {5,1,6}, {5,1,6}, {5,1,6}, {5,1,6},
- {1,5,8}, {11,1,8}, {0,11,8}, {0,10,8},
- {13,1,8}, {12,1,8}, {3,2,8}, {1,4,8},
- {2,1,5}, {2,1,5}, {2,1,5}, {2,1,5},
- {2,1,5}, {2,1,5}, {2,1,5}, {2,1,5},
- {1,2,5}, {1,2,5}, {1,2,5}, {1,2,5},
- {1,2,5}, {1,2,5}, {1,2,5}, {1,2,5},
- {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5},
- {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5},
- {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
- {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
- {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
- {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
- {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
- {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
- {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
- {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3},
- {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4}, /* EOB */
- {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4},
- {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4},
- {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4},
- {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
- {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
- {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
- {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2},
- {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
- {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
- {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
- {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
- {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
- {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
- {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
- {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3},
- {0,4,5}, {0,4,5}, {0,4,5}, {0,4,5},
- {0,4,5}, {0,4,5}, {0,4,5}, {0,4,5},
- {0,5,5}, {0,5,5}, {0,5,5}, {0,5,5},
- {0,5,5}, {0,5,5}, {0,5,5}, {0,5,5},
- {9,1,7}, {9,1,7}, {1,3,7}, {1,3,7},
- {10,1,7}, {10,1,7}, {0,8,7}, {0,8,7},
- {0,9,7}, {0,9,7}, {0,12,8}, {0,13,8},
- {2,3,8}, {4,2,8}, {0,14,8}, {0,15,8}
+ {65, 0, 6}, {65, 0, 6}, {65, 0, 6}, {65, 0, 6}, /* Escape */
+ {7, 1, 7}, {7, 1, 7}, {8, 1, 7}, {8, 1, 7},
+ {6, 1, 7}, {6, 1, 7}, {2, 2, 7}, {2, 2, 7},
+ {0, 7, 6}, {0, 7, 6}, {0, 7, 6}, {0, 7, 6},
+ {0, 6, 6}, {0, 6, 6}, {0, 6, 6}, {0, 6, 6},
+ {4, 1, 6}, {4, 1, 6}, {4, 1, 6}, {4, 1, 6},
+ {5, 1, 6}, {5, 1, 6}, {5, 1, 6}, {5, 1, 6},
+ {1, 5, 8}, {11, 1, 8}, {0, 11, 8}, {0, 10, 8},
+ {13, 1, 8}, {12, 1, 8}, {3, 2, 8}, {1, 4, 8},
+ {2, 1, 5}, {2, 1, 5}, {2, 1, 5}, {2, 1, 5},
+ {2, 1, 5}, {2, 1, 5}, {2, 1, 5}, {2, 1, 5},
+ {1, 2, 5}, {1, 2, 5}, {1, 2, 5}, {1, 2, 5},
+ {1, 2, 5}, {1, 2, 5}, {1, 2, 5}, {1, 2, 5},
+ {3, 1, 5}, {3, 1, 5}, {3, 1, 5}, {3, 1, 5},
+ {3, 1, 5}, {3, 1, 5}, {3, 1, 5}, {3, 1, 5},
+ {1, 1, 3}, {1, 1, 3}, {1, 1, 3}, {1, 1, 3},
+ {1, 1, 3}, {1, 1, 3}, {1, 1, 3}, {1, 1, 3},
+ {1, 1, 3}, {1, 1, 3}, {1, 1, 3}, {1, 1, 3},
+ {1, 1, 3}, {1, 1, 3}, {1, 1, 3}, {1, 1, 3},
+ {1, 1, 3}, {1, 1, 3}, {1, 1, 3}, {1, 1, 3},
+ {1, 1, 3}, {1, 1, 3}, {1, 1, 3}, {1, 1, 3},
+ {1, 1, 3}, {1, 1, 3}, {1, 1, 3}, {1, 1, 3},
+ {1, 1, 3}, {1, 1, 3}, {1, 1, 3}, {1, 1, 3},
+ {64, 0, 4}, {64, 0, 4}, {64, 0, 4}, {64, 0, 4}, /* EOB */
+ {64, 0, 4}, {64, 0, 4}, {64, 0, 4}, {64, 0, 4},
+ {64, 0, 4}, {64, 0, 4}, {64, 0, 4}, {64, 0, 4},
+ {64, 0, 4}, {64, 0, 4}, {64, 0, 4}, {64, 0, 4},
+ {0, 3, 4}, {0, 3, 4}, {0, 3, 4}, {0, 3, 4},
+ {0, 3, 4}, {0, 3, 4}, {0, 3, 4}, {0, 3, 4},
+ {0, 3, 4}, {0, 3, 4}, {0, 3, 4}, {0, 3, 4},
+ {0, 3, 4}, {0, 3, 4}, {0, 3, 4}, {0, 3, 4},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 1, 2}, {0, 1, 2}, {0, 1, 2}, {0, 1, 2},
+ {0, 2, 3}, {0, 2, 3}, {0, 2, 3}, {0, 2, 3},
+ {0, 2, 3}, {0, 2, 3}, {0, 2, 3}, {0, 2, 3},
+ {0, 2, 3}, {0, 2, 3}, {0, 2, 3}, {0, 2, 3},
+ {0, 2, 3}, {0, 2, 3}, {0, 2, 3}, {0, 2, 3},
+ {0, 2, 3}, {0, 2, 3}, {0, 2, 3}, {0, 2, 3},
+ {0, 2, 3}, {0, 2, 3}, {0, 2, 3}, {0, 2, 3},
+ {0, 2, 3}, {0, 2, 3}, {0, 2, 3}, {0, 2, 3},
+ {0, 2, 3}, {0, 2, 3}, {0, 2, 3}, {0, 2, 3},
+ {0, 4, 5}, {0, 4, 5}, {0, 4, 5}, {0, 4, 5},
+ {0, 4, 5}, {0, 4, 5}, {0, 4, 5}, {0, 4, 5},
+ {0, 5, 5}, {0, 5, 5}, {0, 5, 5}, {0, 5, 5},
+ {0, 5, 5}, {0, 5, 5}, {0, 5, 5}, {0, 5, 5},
+ {9, 1, 7}, {9, 1, 7}, {1, 3, 7}, {1, 3, 7},
+ {10, 1, 7}, {10, 1, 7}, {0, 8, 7}, {0, 8, 7},
+ {0, 9, 7}, {0, 9, 7}, {0, 12, 8}, {0, 13, 8},
+ {2, 3, 8}, {4, 2, 8}, {0, 14, 8}, {0, 15, 8}
};
/* Table B-14, DCT coefficients table zero,
@@ -332,8 +335,8 @@ static DCTtab DCTtab0a[252] =
*/
static DCTtab DCTtab1[8] =
{
- {16,1,10}, {5,2,10}, {0,7,10}, {2,3,10},
- {1,4,10}, {15,1,10}, {14,1,10}, {4,2,10}
+ {16, 1, 10}, {5, 2, 10}, {0, 7, 10}, {2, 3, 10},
+ {1, 4, 10}, {15, 1, 10}, {14, 1, 10}, {4, 2, 10}
};
/* Table B-15, DCT coefficients table one,
@@ -341,8 +344,8 @@ static DCTtab DCTtab1[8] =
*/
static DCTtab DCTtab1a[8] =
{
- {5,2,9}, {5,2,9}, {14,1,9}, {14,1,9},
- {2,4,10}, {16,1,10}, {15,1,9}, {15,1,9}
+ {5, 2, 9}, {5, 2, 9}, {14, 1, 9}, {14, 1, 9},
+ {2, 4, 10}, {16, 1, 10}, {15, 1, 9}, {15, 1, 9}
};
/* Table B-14/15, DCT coefficients table zero / one,
@@ -350,10 +353,10 @@ static DCTtab DCTtab1a[8] =
*/
static DCTtab DCTtab2[16] =
{
- {0,11,12}, {8,2,12}, {4,3,12}, {0,10,12},
- {2,4,12}, {7,2,12}, {21,1,12}, {20,1,12},
- {0,9,12}, {19,1,12}, {18,1,12}, {1,5,12},
- {3,3,12}, {0,8,12}, {6,2,12}, {17,1,12}
+ {0, 11, 12}, {8, 2, 12}, {4, 3, 12}, {0, 10, 12},
+ {2, 4, 12}, {7, 2, 12}, {21, 1, 12}, {20, 1, 12},
+ {0, 9, 12}, {19, 1, 12}, {18, 1, 12}, {1, 5, 12},
+ {3, 3, 12}, {0, 8, 12}, {6, 2, 12}, {17, 1, 12}
};
/* Table B-14/15, DCT coefficients table zero / one,
@@ -361,10 +364,10 @@ static DCTtab DCTtab2[16] =
*/
static DCTtab DCTtab3[16] =
{
- {10,2,13}, {9,2,13}, {5,3,13}, {3,4,13},
- {2,5,13}, {1,7,13}, {1,6,13}, {0,15,13},
- {0,14,13}, {0,13,13}, {0,12,13}, {26,1,13},
- {25,1,13}, {24,1,13}, {23,1,13}, {22,1,13}
+ {10, 2, 13}, {9, 2, 13}, {5, 3, 13}, {3, 4, 13},
+ {2, 5, 13}, {1, 7, 13}, {1, 6, 13}, {0, 15, 13},
+ {0, 14, 13}, {0, 13, 13}, {0, 12, 13}, {26, 1, 13},
+ {25, 1, 13}, {24, 1, 13}, {23, 1, 13}, {22, 1, 13}
};
/* Table B-14/15, DCT coefficients table zero / one,
@@ -372,10 +375,10 @@ static DCTtab DCTtab3[16] =
*/
static DCTtab DCTtab4[16] =
{
- {0,31,14}, {0,30,14}, {0,29,14}, {0,28,14},
- {0,27,14}, {0,26,14}, {0,25,14}, {0,24,14},
- {0,23,14}, {0,22,14}, {0,21,14}, {0,20,14},
- {0,19,14}, {0,18,14}, {0,17,14}, {0,16,14}
+ {0, 31, 14}, {0, 30, 14}, {0, 29, 14}, {0, 28, 14},
+ {0, 27, 14}, {0, 26, 14}, {0, 25, 14}, {0, 24, 14},
+ {0, 23, 14}, {0, 22, 14}, {0, 21, 14}, {0, 20, 14},
+ {0, 19, 14}, {0, 18, 14}, {0, 17, 14}, {0, 16, 14}
};
/* Table B-14/15, DCT coefficients table zero / one,
@@ -383,10 +386,10 @@ static DCTtab DCTtab4[16] =
*/
static DCTtab DCTtab5[16] =
{
- {0,40,15}, {0,39,15}, {0,38,15}, {0,37,15},
- {0,36,15}, {0,35,15}, {0,34,15}, {0,33,15},
- {0,32,15}, {1,14,15}, {1,13,15}, {1,12,15},
- {1,11,15}, {1,10,15}, {1,9,15}, {1,8,15}
+ {0, 40, 15}, {0, 39, 15}, {0, 38, 15}, {0, 37, 15},
+ {0, 36, 15}, {0, 35, 15}, {0, 34, 15}, {0, 33, 15},
+ {0, 32, 15}, {1, 14, 15}, {1, 13, 15}, {1, 12, 15},
+ {1, 11, 15}, {1, 10, 15}, {1, 9, 15}, {1, 8, 15}
};
/* Table B-14/15, DCT coefficients table zero / one,
@@ -394,66 +397,66 @@ static DCTtab DCTtab5[16] =
*/
static DCTtab DCTtab6[16] =
{
- {1,18,16}, {1,17,16}, {1,16,16}, {1,15,16},
- {6,3,16}, {16,2,16}, {15,2,16}, {14,2,16},
- {13,2,16}, {12,2,16}, {11,2,16}, {31,1,16},
- {30,1,16}, {29,1,16}, {28,1,16}, {27,1,16}
+ {1, 18, 16}, {1, 17, 16}, {1, 16, 16}, {1, 15, 16},
+ {6, 3, 16}, {16, 2, 16}, {15, 2, 16}, {14, 2, 16},
+ {13, 2, 16}, {12, 2, 16}, {11, 2, 16}, {31, 1, 16},
+ {30, 1, 16}, {29, 1, 16}, {28, 1, 16}, {27, 1, 16}
};
/* Table B-3, macroblock_type in P-pictures, codes 001..1xx */
static VLCtab PMBtab0[8] =
{
- {ERROR_VALUE,0},
- {MACROBLOCK_MOTION_FORWARD,3},
- {MACROBLOCK_PATTERN,2}, {MACROBLOCK_PATTERN,2},
- {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,1},
- {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,1},
- {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,1},
- {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,1}
+ {ERROR_VALUE, 0},
+ {MACROBLOCK_MOTION_FORWARD, 3},
+ {MACROBLOCK_PATTERN, 2}, {MACROBLOCK_PATTERN, 2},
+ {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN, 1},
+ {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN, 1},
+ {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN, 1},
+ {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN, 1}
};
/* Table B-3, macroblock_type in P-pictures, codes 000001..00011x */
static VLCtab PMBtab1[8] =
{
- {ERROR_VALUE,0},
- {MACROBLOCK_QUANT|MACROBLOCK_INTRA,6},
- {MACROBLOCK_QUANT|MACROBLOCK_PATTERN,5}, {MACROBLOCK_QUANT|MACROBLOCK_PATTERN,5},
- {MACROBLOCK_QUANT|MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,5}, {MACROBLOCK_QUANT|MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,5},
- {MACROBLOCK_INTRA,5}, {MACROBLOCK_INTRA,5}
+ {ERROR_VALUE, 0},
+ {MACROBLOCK_QUANT | MACROBLOCK_INTRA, 6},
+ {MACROBLOCK_QUANT | MACROBLOCK_PATTERN, 5}, {MACROBLOCK_QUANT | MACROBLOCK_PATTERN, 5},
+ {MACROBLOCK_QUANT | MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN, 5}, {MACROBLOCK_QUANT | MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN, 5},
+ {MACROBLOCK_INTRA, 5}, {MACROBLOCK_INTRA, 5}
};
/* Table B-4, macroblock_type in B-pictures, codes 0010..11xx */
static VLCtab BMBtab0[16] =
{
- {ERROR_VALUE,0},
- {ERROR_VALUE,0},
- {MACROBLOCK_MOTION_FORWARD,4},
- {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,4},
- {MACROBLOCK_MOTION_BACKWARD,3},
- {MACROBLOCK_MOTION_BACKWARD,3},
- {MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,3},
- {MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,3},
- {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD,2},
- {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD,2},
- {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD,2},
- {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD,2},
- {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,2},
- {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,2},
- {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,2},
- {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,2}
+ {ERROR_VALUE, 0},
+ {ERROR_VALUE, 0},
+ {MACROBLOCK_MOTION_FORWARD, 4},
+ {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN, 4},
+ {MACROBLOCK_MOTION_BACKWARD, 3},
+ {MACROBLOCK_MOTION_BACKWARD, 3},
+ {MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN, 3},
+ {MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN, 3},
+ {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD, 2},
+ {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD, 2},
+ {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD, 2},
+ {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD, 2},
+ {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN, 2},
+ {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN, 2},
+ {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN, 2},
+ {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN, 2}
};
/* Table B-4, macroblock_type in B-pictures, codes 000001..00011x */
static VLCtab BMBtab1[8] =
{
- {ERROR_VALUE,0},
- {MACROBLOCK_QUANT|MACROBLOCK_INTRA,6},
- {MACROBLOCK_QUANT|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,6},
- {MACROBLOCK_QUANT|MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,6},
- {MACROBLOCK_QUANT|MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,5},
- {MACROBLOCK_QUANT|MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,5},
- {MACROBLOCK_INTRA,5},
- {MACROBLOCK_INTRA,5}
+ {ERROR_VALUE, 0},
+ {MACROBLOCK_QUANT | MACROBLOCK_INTRA, 6},
+ {MACROBLOCK_QUANT | MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN, 6},
+ {MACROBLOCK_QUANT | MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN, 6},
+ {MACROBLOCK_QUANT | MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN, 5},
+ {MACROBLOCK_QUANT | MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN, 5},
+ {MACROBLOCK_INTRA, 5},
+ {MACROBLOCK_INTRA, 5}
};
//
@@ -462,251 +465,251 @@ static VLCtab BMBtab1[8] =
void CMPEG2Dec::Initialize_Buffer()
{
- Rdptr = Rdbfr + BUFFER_SIZE;
- Rdmax = Rdptr;
+ Rdptr = Rdbfr + BUFFER_SIZE;
+ Rdmax = Rdptr;
- if (SystemStream_Flag)
- {
- if (Rdptr >= Rdmax)
- Next_Packet();
- CurrentBfr = *Rdptr++ << 24;
+ if(SystemStream_Flag)
+ {
+ if(Rdptr >= Rdmax)
+ Next_Packet();
+ CurrentBfr = *Rdptr++ << 24;
- if (Rdptr >= Rdmax)
- Next_Packet();
- CurrentBfr += *Rdptr++ << 16;
+ if(Rdptr >= Rdmax)
+ Next_Packet();
+ CurrentBfr += *Rdptr++ << 16;
- if (Rdptr >= Rdmax)
- Next_Packet();
- CurrentBfr += *Rdptr++ << 8;
+ if(Rdptr >= Rdmax)
+ Next_Packet();
+ CurrentBfr += *Rdptr++ << 8;
- if (Rdptr >= Rdmax)
- Next_Packet();
- CurrentBfr += *Rdptr++;
+ if(Rdptr >= Rdmax)
+ Next_Packet();
+ CurrentBfr += *Rdptr++;
- Fill_Next();
- }
- else
- {
- Fill_Buffer();
+ Fill_Next();
+ }
+ else
+ {
+ Fill_Buffer();
- CurrentBfr = (*Rdptr << 24) + (*(Rdptr+1) << 16) + (*(Rdptr+2) << 8) + *(Rdptr+3);
- Rdptr += 4;
+ CurrentBfr = (*Rdptr << 24) + (*(Rdptr + 1) << 16) + (*(Rdptr + 2) << 8) + *(Rdptr + 3);
+ Rdptr += 4;
- Fill_Next();
- }
+ Fill_Next();
+ }
- BitsLeft = 32;
+ BitsLeft = 32;
}
unsigned int CMPEG2Dec::Get_Bits_All(unsigned int N)
{
- N -= BitsLeft;
- Val = (CurrentBfr << (32 - BitsLeft)) >> (32 - BitsLeft);
+ N -= BitsLeft;
+ Val = (CurrentBfr << (32 - BitsLeft)) >> (32 - BitsLeft);
- if (N != 0)
- Val = (Val << N) + (NextBfr >> (32 - N));
+ if(N != 0)
+ Val = (Val << N) + (NextBfr >> (32 - N));
- CurrentBfr = NextBfr;
- BitsLeft = 32 - N;
- Fill_Next();
+ CurrentBfr = NextBfr;
+ BitsLeft = 32 - N;
+ Fill_Next();
- return Val;
+ return Val;
}
void CMPEG2Dec::Flush_Buffer_All(unsigned int N)
{
- CurrentBfr = NextBfr;
- BitsLeft = BitsLeft + 32 - N;
- Fill_Next();
+ CurrentBfr = NextBfr;
+ BitsLeft = BitsLeft + 32 - N;
+ Fill_Next();
}
void CMPEG2Dec::Next_Packet()
{
- unsigned int code, Packet_Length, Packet_Header_Length;
-
- for (;;)
- {
- code = Get_Short();
- code = (code<<16) + Get_Short();
-
- // remove system layer byte stuffing
- while ((code & 0xffffff00) != 0x00000100)
- code = (code<<8) + Get_Byte();
-
- switch (code)
- {
- case PACK_START_CODE:
- Rdptr += 8;
- break;
-
- case VIDEO_ELEMENTARY_STREAM:
- Packet_Length = Get_Short();
- Rdmax = Rdptr + Packet_Length;
-
- code = Get_Byte();
-
- if ((code & 0xc0)==0x80)
- {
- code = Get_Byte();
- Packet_Header_Length = Get_Byte();
-
- Rdptr += Packet_Header_Length;
- return;
- }
- else
- Rdptr += Packet_Length-1;
- break;
-
- default:
- if (code>=SYSTEM_START_CODE)
- {
- code = Get_Short();
- Rdptr += code;
- }
- break;
- }
- }
+ unsigned int code, Packet_Length, Packet_Header_Length;
+
+ for(;;)
+ {
+ code = Get_Short();
+ code = (code << 16) + Get_Short();
+
+ // remove system layer byte stuffing
+ while((code & 0xffffff00) != 0x00000100)
+ code = (code << 8) + Get_Byte();
+
+ switch(code)
+ {
+ case PACK_START_CODE:
+ Rdptr += 8;
+ break;
+
+ case VIDEO_ELEMENTARY_STREAM:
+ Packet_Length = Get_Short();
+ Rdmax = Rdptr + Packet_Length;
+
+ code = Get_Byte();
+
+ if((code & 0xc0) == 0x80)
+ {
+ code = Get_Byte();
+ Packet_Header_Length = Get_Byte();
+
+ Rdptr += Packet_Header_Length;
+ return;
+ }
+ else
+ Rdptr += Packet_Length - 1;
+ break;
+
+ default:
+ if(code >= SYSTEM_START_CODE)
+ {
+ code = Get_Short();
+ Rdptr += code;
+ }
+ break;
+ }
+ }
}
void CMPEG2Dec::Fill_Buffer()
{
- Read = _read(Infile[File_Flag], Rdbfr, BUFFER_SIZE);
+ Read = _read(Infile[File_Flag], Rdbfr, BUFFER_SIZE);
- if (Read < BUFFER_SIZE)
- Next_File();
+ if(Read < BUFFER_SIZE)
+ Next_File();
- if (KeyOp_Flag && (Rdbfr[20] & 0x10))
- {
- BufferOp(Rdbfr, lfsr0, lfsr1);
- Rdbfr[20] &= ~0x10;
- }
+ if(KeyOp_Flag && (Rdbfr[20] & 0x10))
+ {
+ BufferOp(Rdbfr, lfsr0, lfsr1);
+ Rdbfr[20] &= ~0x10;
+ }
- Rdptr = Rdbfr;
+ Rdptr = Rdbfr;
- if (SystemStream_Flag)
- Rdmax -= BUFFER_SIZE;
+ if(SystemStream_Flag)
+ Rdmax -= BUFFER_SIZE;
}
void CMPEG2Dec::Next_File()
{
- if (File_Flag < File_Limit-1)
- File_Flag ++;
+ if(File_Flag < File_Limit - 1)
+ File_Flag ++;
- _lseeki64(Infile[File_Flag], 0, SEEK_SET);
- _read(Infile[File_Flag], Rdbfr + Read, BUFFER_SIZE - Read);
+ _lseeki64(Infile[File_Flag], 0, SEEK_SET);
+ _read(Infile[File_Flag], Rdbfr + Read, BUFFER_SIZE - Read);
}
unsigned int CMPEG2Dec::Show_Bits(unsigned int N)
{
- if (N <= BitsLeft)
- return (CurrentBfr << (32 - BitsLeft)) >> (32 - N);
- else
- {
- N -= BitsLeft;
- return (((CurrentBfr << (32 - BitsLeft)) >> (32 - BitsLeft)) << N) + (NextBfr >> (32 - N));
- }
+ if(N <= BitsLeft)
+ return (CurrentBfr << (32 - BitsLeft)) >> (32 - N);
+ else
+ {
+ N -= BitsLeft;
+ return (((CurrentBfr << (32 - BitsLeft)) >> (32 - BitsLeft)) << N) + (NextBfr >> (32 - N));
+ }
}
unsigned int CMPEG2Dec::Get_Bits(unsigned int N)
{
- if (N < BitsLeft)
- {
- Val = (CurrentBfr << (32 - BitsLeft)) >> (32 - N);
- BitsLeft -= N;
- return Val;
- }
- else
- return Get_Bits_All(N);
+ if(N < BitsLeft)
+ {
+ Val = (CurrentBfr << (32 - BitsLeft)) >> (32 - N);
+ BitsLeft -= N;
+ return Val;
+ }
+ else
+ return Get_Bits_All(N);
}
void CMPEG2Dec::Flush_Buffer(unsigned int N)
{
- if (N < BitsLeft)
- BitsLeft -= N;
- else
- Flush_Buffer_All(N);
+ if(N < BitsLeft)
+ BitsLeft -= N;
+ else
+ Flush_Buffer_All(N);
}
void CMPEG2Dec::Fill_Next()
{
- if (SystemStream_Flag && Rdptr>=Rdmax-4)
- {
- if (Rdptr >= Rdmax)
- Next_Packet();
- NextBfr = Get_Byte() << 24;
-
- if (Rdptr >= Rdmax)
- Next_Packet();
- NextBfr += Get_Byte() << 16;
-
- if (Rdptr >= Rdmax)
- Next_Packet();
- NextBfr += Get_Byte() << 8;
-
- if (Rdptr >= Rdmax)
- Next_Packet();
- NextBfr += Get_Byte();
- }
- else if (Rdptr < Rdbfr+BUFFER_SIZE-4)
- {
- NextBfr = (*Rdptr << 24) + (*(Rdptr+1) << 16) + (*(Rdptr+2) << 8) + *(Rdptr+3);
- Rdptr += 4;
- }
- else
- {
- if (Rdptr >= Rdbfr+BUFFER_SIZE)
- Fill_Buffer();
- NextBfr = *Rdptr++ << 24;
-
- if (Rdptr >= Rdbfr+BUFFER_SIZE)
- Fill_Buffer();
- NextBfr += *Rdptr++ << 16;
-
- if (Rdptr >= Rdbfr+BUFFER_SIZE)
- Fill_Buffer();
- NextBfr += *Rdptr++ << 8;
-
- if (Rdptr >= Rdbfr+BUFFER_SIZE)
- Fill_Buffer();
- NextBfr += *Rdptr++;
- }
+ if(SystemStream_Flag && Rdptr >= Rdmax - 4)
+ {
+ if(Rdptr >= Rdmax)
+ Next_Packet();
+ NextBfr = Get_Byte() << 24;
+
+ if(Rdptr >= Rdmax)
+ Next_Packet();
+ NextBfr += Get_Byte() << 16;
+
+ if(Rdptr >= Rdmax)
+ Next_Packet();
+ NextBfr += Get_Byte() << 8;
+
+ if(Rdptr >= Rdmax)
+ Next_Packet();
+ NextBfr += Get_Byte();
+ }
+ else if(Rdptr < Rdbfr + BUFFER_SIZE - 4)
+ {
+ NextBfr = (*Rdptr << 24) + (*(Rdptr + 1) << 16) + (*(Rdptr + 2) << 8) + *(Rdptr + 3);
+ Rdptr += 4;
+ }
+ else
+ {
+ if(Rdptr >= Rdbfr + BUFFER_SIZE)
+ Fill_Buffer();
+ NextBfr = *Rdptr++ << 24;
+
+ if(Rdptr >= Rdbfr + BUFFER_SIZE)
+ Fill_Buffer();
+ NextBfr += *Rdptr++ << 16;
+
+ if(Rdptr >= Rdbfr + BUFFER_SIZE)
+ Fill_Buffer();
+ NextBfr += *Rdptr++ << 8;
+
+ if(Rdptr >= Rdbfr + BUFFER_SIZE)
+ Fill_Buffer();
+ NextBfr += *Rdptr++;
+ }
}
unsigned int CMPEG2Dec::Get_Byte()
{
- while (Rdptr >= (Rdbfr + BUFFER_SIZE))
- {
- Read = _read(Infile[File_Flag], Rdbfr, BUFFER_SIZE);
+ while(Rdptr >= (Rdbfr + BUFFER_SIZE))
+ {
+ Read = _read(Infile[File_Flag], Rdbfr, BUFFER_SIZE);
- if (Read < BUFFER_SIZE)
- Next_File();
+ if(Read < BUFFER_SIZE)
+ Next_File();
- if (KeyOp_Flag && (Rdbfr[20] & 0x10))
- {
- BufferOp(Rdbfr, lfsr0, lfsr1);
- Rdbfr[20] &= ~0x10;
- }
+ if(KeyOp_Flag && (Rdbfr[20] & 0x10))
+ {
+ BufferOp(Rdbfr, lfsr0, lfsr1);
+ Rdbfr[20] &= ~0x10;
+ }
- Rdptr -= BUFFER_SIZE;
- Rdmax -= BUFFER_SIZE;
- }
+ Rdptr -= BUFFER_SIZE;
+ Rdmax -= BUFFER_SIZE;
+ }
- return *Rdptr++;
+ return *Rdptr++;
}
unsigned int CMPEG2Dec::Get_Short()
{
- unsigned int i = Get_Byte();
- return (i<<8) + Get_Byte();
+ unsigned int i = Get_Byte();
+ return (i << 8) + Get_Byte();
}
void CMPEG2Dec::next_start_code()
{
- Flush_Buffer(BitsLeft & 7);
+ Flush_Buffer(BitsLeft & 7);
- while (Show_Bits(24) != 1)
- Flush_Buffer(8);
+ while(Show_Bits(24) != 1)
+ Flush_Buffer(8);
}
//
@@ -715,402 +718,402 @@ void CMPEG2Dec::next_start_code()
int CMPEG2Dec::Get_Hdr()
{
- for (;;)
- {
- /* look for next_start_code */
- next_start_code();
-
- switch (Get_Bits(32))
- {
- case SEQUENCE_HEADER_CODE:
- sequence_header();
- break;
-
- case GROUP_START_CODE:
- group_of_pictures_header();
- break;
-
- case PICTURE_START_CODE:
- picture_header();
- return 1;
- }
- }
+ for(;;)
+ {
+ /* look for next_start_code */
+ next_start_code();
+
+ switch(Get_Bits(32))
+ {
+ case SEQUENCE_HEADER_CODE:
+ sequence_header();
+ break;
+
+ case GROUP_START_CODE:
+ group_of_pictures_header();
+ break;
+
+ case PICTURE_START_CODE:
+ picture_header();
+ return 1;
+ }
+ }
}
/* decode group of pictures header */
/* ISO/IEC 13818-2 section 6.2.2.6 */
void CMPEG2Dec::group_of_pictures_header()
{
- int gop_hour;
- int gop_minute;
- int gop_sec;
- int gop_frame;
-
- int drop_flag;
- int closed_gop;
- int broken_link;
-
- drop_flag = Get_Bits(1);
- gop_hour = Get_Bits(5);
- gop_minute = Get_Bits(6);
- Flush_Buffer(1); // marker bit
- gop_sec = Get_Bits(6);
- gop_frame = Get_Bits(6);
- closed_gop = Get_Bits(1);
- broken_link = Get_Bits(1);
-
- extension_and_user_data();
+ int gop_hour;
+ int gop_minute;
+ int gop_sec;
+ int gop_frame;
+
+ int drop_flag;
+ int closed_gop;
+ int broken_link;
+
+ drop_flag = Get_Bits(1);
+ gop_hour = Get_Bits(5);
+ gop_minute = Get_Bits(6);
+ Flush_Buffer(1); // marker bit
+ gop_sec = Get_Bits(6);
+ gop_frame = Get_Bits(6);
+ closed_gop = Get_Bits(1);
+ broken_link = Get_Bits(1);
+
+ extension_and_user_data();
}
/* decode picture header */
/* ISO/IEC 13818-2 section 6.2.3 */
void CMPEG2Dec::picture_header()
{
- int vbv_delay;
- int full_pel_forward_vector;
- int forward_f_code;
- int full_pel_backward_vector;
- int backward_f_code;
- int Extra_Information_Byte_Count;
-
- temporal_reference = Get_Bits(10);
- picture_coding_type = Get_Bits(3);
- vbv_delay = Get_Bits(16);
-
- if (picture_coding_type==P_TYPE || picture_coding_type==B_TYPE)
- {
- full_pel_forward_vector = Get_Bits(1);
- forward_f_code = Get_Bits(3);
- }
-
- if (picture_coding_type==B_TYPE)
- {
- full_pel_backward_vector = Get_Bits(1);
- backward_f_code = Get_Bits(3);
- }
-
- Extra_Information_Byte_Count = extra_bit_information();
- extension_and_user_data();
+ int vbv_delay;
+ int full_pel_forward_vector;
+ int forward_f_code;
+ int full_pel_backward_vector;
+ int backward_f_code;
+ int Extra_Information_Byte_Count;
+
+ temporal_reference = Get_Bits(10);
+ picture_coding_type = Get_Bits(3);
+ vbv_delay = Get_Bits(16);
+
+ if(picture_coding_type == P_TYPE || picture_coding_type == B_TYPE)
+ {
+ full_pel_forward_vector = Get_Bits(1);
+ forward_f_code = Get_Bits(3);
+ }
+
+ if(picture_coding_type == B_TYPE)
+ {
+ full_pel_backward_vector = Get_Bits(1);
+ backward_f_code = Get_Bits(3);
+ }
+
+ Extra_Information_Byte_Count = extra_bit_information();
+ extension_and_user_data();
}
/* decode sequence header */
void CMPEG2Dec::sequence_header()
{
- int frame_rate_code;
- int vbv_buffer_size;
- int aspect_ratio_information;
- int bit_rate_value;
-
- int constrained_parameters_flag;
- int i;
-
- horizontal_size = Get_Bits(12);
- vertical_size = Get_Bits(12);
- aspect_ratio_information = Get_Bits(4);
- frame_rate_code = Get_Bits(4);
- bit_rate_value = Get_Bits(18);
- Flush_Buffer(1); // marker bit
- vbv_buffer_size = Get_Bits(10);
- constrained_parameters_flag = Get_Bits(1);
-
- if (load_intra_quantizer_matrix = Get_Bits(1))
- {
- for (i=0; i<64; i++)
- intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
- }
- else
- {
- for (i=0; i<64; i++)
- intra_quantizer_matrix[i] = default_intra_quantizer_matrix[i];
- }
-
- if (load_non_intra_quantizer_matrix = Get_Bits(1))
- {
- for (i=0; i<64; i++)
- non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
- }
- else
- {
- for (i=0; i<64; i++)
- non_intra_quantizer_matrix[i] = 16;
- }
-
- /* copy luminance to chrominance matrices */
- for (i=0; i<64; i++)
- {
- chroma_intra_quantizer_matrix[i] = intra_quantizer_matrix[i];
- chroma_non_intra_quantizer_matrix[i] = non_intra_quantizer_matrix[i];
- }
- extension_and_user_data();
+ int frame_rate_code;
+ int vbv_buffer_size;
+ int aspect_ratio_information;
+ int bit_rate_value;
+
+ int constrained_parameters_flag;
+ int i;
+
+ horizontal_size = Get_Bits(12);
+ vertical_size = Get_Bits(12);
+ aspect_ratio_information = Get_Bits(4);
+ frame_rate_code = Get_Bits(4);
+ bit_rate_value = Get_Bits(18);
+ Flush_Buffer(1); // marker bit
+ vbv_buffer_size = Get_Bits(10);
+ constrained_parameters_flag = Get_Bits(1);
+
+ if(load_intra_quantizer_matrix = Get_Bits(1))
+ {
+ for(i = 0; i < 64; i++)
+ intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
+ }
+ else
+ {
+ for(i = 0; i < 64; i++)
+ intra_quantizer_matrix[i] = default_intra_quantizer_matrix[i];
+ }
+
+ if(load_non_intra_quantizer_matrix = Get_Bits(1))
+ {
+ for(i = 0; i < 64; i++)
+ non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
+ }
+ else
+ {
+ for(i = 0; i < 64; i++)
+ non_intra_quantizer_matrix[i] = 16;
+ }
+
+ /* copy luminance to chrominance matrices */
+ for(i = 0; i < 64; i++)
+ {
+ chroma_intra_quantizer_matrix[i] = intra_quantizer_matrix[i];
+ chroma_non_intra_quantizer_matrix[i] = non_intra_quantizer_matrix[i];
+ }
+ extension_and_user_data();
}
/* decode slice header */
/* ISO/IEC 13818-2 section 6.2.4 */
int CMPEG2Dec::slice_header()
{
- int slice_vertical_position_extension;
- int quantizer_scale_code;
- int slice_picture_id_enable = 0;
- int slice_picture_id = 0;
- int extra_information_slice = 0;
+ int slice_vertical_position_extension;
+ int quantizer_scale_code;
+ int slice_picture_id_enable = 0;
+ int slice_picture_id = 0;
+ int extra_information_slice = 0;
- slice_vertical_position_extension = vertical_size>2800 ? Get_Bits(3) : 0;
+ slice_vertical_position_extension = vertical_size > 2800 ? Get_Bits(3) : 0;
- quantizer_scale_code = Get_Bits(5);
- quantizer_scale = q_scale_type ? Non_Linear_quantizer_scale[quantizer_scale_code] : quantizer_scale_code<<1;
+ quantizer_scale_code = Get_Bits(5);
+ quantizer_scale = q_scale_type ? Non_Linear_quantizer_scale[quantizer_scale_code] : quantizer_scale_code << 1;
- /* slice_id introduced in March 1995 as part of the video corridendum
- (after the IS was drafted in November 1994) */
- if (Get_Bits(1))
- {
- Get_Bits(1); // intra slice
+ /* slice_id introduced in March 1995 as part of the video corridendum
+ (after the IS was drafted in November 1994) */
+ if(Get_Bits(1))
+ {
+ Get_Bits(1); // intra slice
- slice_picture_id_enable = Get_Bits(1);
- slice_picture_id = Get_Bits(6);
+ slice_picture_id_enable = Get_Bits(1);
+ slice_picture_id = Get_Bits(6);
- extra_information_slice = extra_bit_information();
- }
+ extra_information_slice = extra_bit_information();
+ }
- return slice_vertical_position_extension;
+ return slice_vertical_position_extension;
}
/* decode extension and user data */
/* ISO/IEC 13818-2 section 6.2.2.2 */
void CMPEG2Dec::extension_and_user_data()
{
- int code, ext_ID;
-
- next_start_code();
-
- while ((code = Show_Bits(32))==EXTENSION_START_CODE || code==USER_DATA_START_CODE)
- {
- if (code==EXTENSION_START_CODE)
- {
- Flush_Buffer(32);
- ext_ID = Get_Bits(4);
-
- switch (ext_ID)
- {
- case SEQUENCE_EXTENSION_ID:
- sequence_extension();
- break;
-
- case SEQUENCE_DISPLAY_EXTENSION_ID:
- sequence_display_extension();
- break;
-
- case QUANT_MATRIX_EXTENSION_ID:
- quant_matrix_extension();
- break;
-
- case PICTURE_DISPLAY_EXTENSION_ID:
- picture_display_extension();
- break;
-
- case PICTURE_CODING_EXTENSION_ID:
- picture_coding_extension();
- break;
-
- case COPYRIGHT_EXTENSION_ID:
- copyright_extension();
- break;
- }
- next_start_code();
- }
- else
- {
- Flush_Buffer(32);
- next_start_code();
- }
- }
+ int code, ext_ID;
+
+ next_start_code();
+
+ while((code = Show_Bits(32)) == EXTENSION_START_CODE || code == USER_DATA_START_CODE)
+ {
+ if(code == EXTENSION_START_CODE)
+ {
+ Flush_Buffer(32);
+ ext_ID = Get_Bits(4);
+
+ switch(ext_ID)
+ {
+ case SEQUENCE_EXTENSION_ID:
+ sequence_extension();
+ break;
+
+ case SEQUENCE_DISPLAY_EXTENSION_ID:
+ sequence_display_extension();
+ break;
+
+ case QUANT_MATRIX_EXTENSION_ID:
+ quant_matrix_extension();
+ break;
+
+ case PICTURE_DISPLAY_EXTENSION_ID:
+ picture_display_extension();
+ break;
+
+ case PICTURE_CODING_EXTENSION_ID:
+ picture_coding_extension();
+ break;
+
+ case COPYRIGHT_EXTENSION_ID:
+ copyright_extension();
+ break;
+ }
+ next_start_code();
+ }
+ else
+ {
+ Flush_Buffer(32);
+ next_start_code();
+ }
+ }
}
/* decode sequence extension */
/* ISO/IEC 13818-2 section 6.2.2.3 */
void CMPEG2Dec::sequence_extension()
{
- int profile_and_level_indication;
- int low_delay;
- int frame_rate_extension_n;
- int frame_rate_extension_d;
-
- int horizontal_size_extension;
- int vertical_size_extension;
- int bit_rate_extension;
- int vbv_buffer_size_extension;
-
- profile_and_level_indication = Get_Bits(8);
- progressive_sequence = Get_Bits(1);
- chroma_format = Get_Bits(2);
- horizontal_size_extension = Get_Bits(2);
- vertical_size_extension = Get_Bits(2);
- bit_rate_extension = Get_Bits(12);
- Flush_Buffer(1); // marker bit
- vbv_buffer_size_extension = Get_Bits(8);
- low_delay = Get_Bits(1);
-
- frame_rate_extension_n = Get_Bits(2);
- frame_rate_extension_d = Get_Bits(5);
-
- horizontal_size = (horizontal_size_extension<<12) | (horizontal_size&0x0fff);
- vertical_size = (vertical_size_extension<<12) | (vertical_size&0x0fff);
+ int profile_and_level_indication;
+ int low_delay;
+ int frame_rate_extension_n;
+ int frame_rate_extension_d;
+
+ int horizontal_size_extension;
+ int vertical_size_extension;
+ int bit_rate_extension;
+ int vbv_buffer_size_extension;
+
+ profile_and_level_indication = Get_Bits(8);
+ progressive_sequence = Get_Bits(1);
+ chroma_format = Get_Bits(2);
+ horizontal_size_extension = Get_Bits(2);
+ vertical_size_extension = Get_Bits(2);
+ bit_rate_extension = Get_Bits(12);
+ Flush_Buffer(1); // marker bit
+ vbv_buffer_size_extension = Get_Bits(8);
+ low_delay = Get_Bits(1);
+
+ frame_rate_extension_n = Get_Bits(2);
+ frame_rate_extension_d = Get_Bits(5);
+
+ horizontal_size = (horizontal_size_extension << 12) | (horizontal_size & 0x0fff);
+ vertical_size = (vertical_size_extension << 12) | (vertical_size & 0x0fff);
}
/* decode sequence display extension */
void CMPEG2Dec::sequence_display_extension()
{
- int video_format;
- int color_description;
- int color_primaries;
- int transfer_characteristics;
- int matrix_coefficients;
- int display_horizontal_size;
- int display_vertical_size;
-
- video_format = Get_Bits(3);
- color_description = Get_Bits(1);
-
- if (color_description)
- {
- color_primaries = Get_Bits(8);
- transfer_characteristics = Get_Bits(8);
- matrix_coefficients = Get_Bits(8);
- }
-
- display_horizontal_size = Get_Bits(14);
- Flush_Buffer(1); // marker bit
- display_vertical_size = Get_Bits(14);
+ int video_format;
+ int color_description;
+ int color_primaries;
+ int transfer_characteristics;
+ int matrix_coefficients;
+ int display_horizontal_size;
+ int display_vertical_size;
+
+ video_format = Get_Bits(3);
+ color_description = Get_Bits(1);
+
+ if(color_description)
+ {
+ color_primaries = Get_Bits(8);
+ transfer_characteristics = Get_Bits(8);
+ matrix_coefficients = Get_Bits(8);
+ }
+
+ display_horizontal_size = Get_Bits(14);
+ Flush_Buffer(1); // marker bit
+ display_vertical_size = Get_Bits(14);
}
/* decode quant matrix entension */
/* ISO/IEC 13818-2 section 6.2.3.2 */
void CMPEG2Dec::quant_matrix_extension()
{
- int i;
+ int i;
- if (load_intra_quantizer_matrix = Get_Bits(1))
- for (i=0; i<64; i++)
- chroma_intra_quantizer_matrix[scan[ZIG_ZAG][i]]
- = intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
+ if(load_intra_quantizer_matrix = Get_Bits(1))
+ for(i = 0; i < 64; i++)
+ chroma_intra_quantizer_matrix[scan[ZIG_ZAG][i]]
+ = intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
- if (load_non_intra_quantizer_matrix = Get_Bits(1))
- for (i=0; i<64; i++)
- chroma_non_intra_quantizer_matrix[scan[ZIG_ZAG][i]]
- = non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
+ if(load_non_intra_quantizer_matrix = Get_Bits(1))
+ for(i = 0; i < 64; i++)
+ chroma_non_intra_quantizer_matrix[scan[ZIG_ZAG][i]]
+ = non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
- if (load_chroma_intra_quantizer_matrix = Get_Bits(1))
- for (i=0; i<64; i++)
- chroma_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
+ if(load_chroma_intra_quantizer_matrix = Get_Bits(1))
+ for(i = 0; i < 64; i++)
+ chroma_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
- if (load_chroma_non_intra_quantizer_matrix = Get_Bits(1))
- for (i=0; i<64; i++)
- chroma_non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
+ if(load_chroma_non_intra_quantizer_matrix = Get_Bits(1))
+ for(i = 0; i < 64; i++)
+ chroma_non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8);
}
/* decode picture display extension */
/* ISO/IEC 13818-2 section 6.2.3.3. */
void CMPEG2Dec::picture_display_extension()
{
- int frame_center_horizontal_offset[3];
- int frame_center_vertical_offset[3];
-
- int i;
- int number_of_frame_center_offsets;
-
- /* based on ISO/IEC 13818-2 section 6.3.12
- (November 1994) Picture display extensions */
-
- /* derive number_of_frame_center_offsets */
- if (progressive_sequence)
- {
- if (repeat_first_field)
- {
- if (top_field_first)
- number_of_frame_center_offsets = 3;
- else
- number_of_frame_center_offsets = 2;
- }
- else
- number_of_frame_center_offsets = 1;
- }
- else
- {
- if (picture_structure!=FRAME_PICTURE)
- number_of_frame_center_offsets = 1;
- else
- {
- if (repeat_first_field)
- number_of_frame_center_offsets = 3;
- else
- number_of_frame_center_offsets = 2;
- }
- }
-
- /* now parse */
- for (i=0; i<number_of_frame_center_offsets; i++)
- {
- frame_center_horizontal_offset[i] = Get_Bits(16);
- Flush_Buffer(1); // marker bit
-
- frame_center_vertical_offset[i] = Get_Bits(16);
- Flush_Buffer(1); // marker bit
- }
+ int frame_center_horizontal_offset[3];
+ int frame_center_vertical_offset[3];
+
+ int i;
+ int number_of_frame_center_offsets;
+
+ /* based on ISO/IEC 13818-2 section 6.3.12
+ (November 1994) Picture display extensions */
+
+ /* derive number_of_frame_center_offsets */
+ if(progressive_sequence)
+ {
+ if(repeat_first_field)
+ {
+ if(top_field_first)
+ number_of_frame_center_offsets = 3;
+ else
+ number_of_frame_center_offsets = 2;
+ }
+ else
+ number_of_frame_center_offsets = 1;
+ }
+ else
+ {
+ if(picture_structure != FRAME_PICTURE)
+ number_of_frame_center_offsets = 1;
+ else
+ {
+ if(repeat_first_field)
+ number_of_frame_center_offsets = 3;
+ else
+ number_of_frame_center_offsets = 2;
+ }
+ }
+
+ /* now parse */
+ for(i = 0; i < number_of_frame_center_offsets; i++)
+ {
+ frame_center_horizontal_offset[i] = Get_Bits(16);
+ Flush_Buffer(1); // marker bit
+
+ frame_center_vertical_offset[i] = Get_Bits(16);
+ Flush_Buffer(1); // marker bit
+ }
}
/* decode picture coding extension */
void CMPEG2Dec::picture_coding_extension()
{
- int chroma_420_type;
- int composite_display_flag;
- int v_axis;
- int field_sequence;
- int sub_carrier;
- int burst_amplitude;
- int sub_carrier_phase;
-
- f_code[0][0] = Get_Bits(4);
- f_code[0][1] = Get_Bits(4);
- f_code[1][0] = Get_Bits(4);
- f_code[1][1] = Get_Bits(4);
-
- intra_dc_precision = Get_Bits(2);
- picture_structure = Get_Bits(2);
- top_field_first = Get_Bits(1);
- frame_pred_frame_dct = Get_Bits(1);
- concealment_motion_vectors = Get_Bits(1);
- q_scale_type = Get_Bits(1);
- intra_vlc_format = Get_Bits(1);
- alternate_scan = Get_Bits(1);
- repeat_first_field = Get_Bits(1);
- chroma_420_type = Get_Bits(1);
- progressive_frame = Get_Bits(1);
- composite_display_flag = Get_Bits(1);
-
- pf_current = progressive_frame;
-
- if (composite_display_flag)
- {
- v_axis = Get_Bits(1);
- field_sequence = Get_Bits(3);
- sub_carrier = Get_Bits(1);
- burst_amplitude = Get_Bits(7);
- sub_carrier_phase = Get_Bits(8);
- }
+ int chroma_420_type;
+ int composite_display_flag;
+ int v_axis;
+ int field_sequence;
+ int sub_carrier;
+ int burst_amplitude;
+ int sub_carrier_phase;
+
+ f_code[0][0] = Get_Bits(4);
+ f_code[0][1] = Get_Bits(4);
+ f_code[1][0] = Get_Bits(4);
+ f_code[1][1] = Get_Bits(4);
+
+ intra_dc_precision = Get_Bits(2);
+ picture_structure = Get_Bits(2);
+ top_field_first = Get_Bits(1);
+ frame_pred_frame_dct = Get_Bits(1);
+ concealment_motion_vectors = Get_Bits(1);
+ q_scale_type = Get_Bits(1);
+ intra_vlc_format = Get_Bits(1);
+ alternate_scan = Get_Bits(1);
+ repeat_first_field = Get_Bits(1);
+ chroma_420_type = Get_Bits(1);
+ progressive_frame = Get_Bits(1);
+ composite_display_flag = Get_Bits(1);
+
+ pf_current = progressive_frame;
+
+ if(composite_display_flag)
+ {
+ v_axis = Get_Bits(1);
+ field_sequence = Get_Bits(3);
+ sub_carrier = Get_Bits(1);
+ burst_amplitude = Get_Bits(7);
+ sub_carrier_phase = Get_Bits(8);
+ }
}
/* decode extra bit information */
/* ISO/IEC 13818-2 section 6.2.3.4. */
int CMPEG2Dec::extra_bit_information()
{
- int Byte_Count = 0;
+ int Byte_Count = 0;
- while (Get_Bits(1))
- {
- Flush_Buffer(8);
- Byte_Count ++;
- }
+ while(Get_Bits(1))
+ {
+ Flush_Buffer(8);
+ Byte_Count ++;
+ }
- return(Byte_Count);
+ return(Byte_Count);
}
/* Copyright extension */
@@ -1118,118 +1121,119 @@ int CMPEG2Dec::extra_bit_information()
/* (header added in November, 1994 to the IS document) */
void CMPEG2Dec::copyright_extension()
{
- int copyright_flag;
- int copyright_identifier;
- int original_or_copy;
- int copyright_number_1;
- int copyright_number_2;
- int copyright_number_3;
-
- int reserved_data;
-
- copyright_flag = Get_Bits(1);
- copyright_identifier = Get_Bits(8);
- original_or_copy = Get_Bits(1);
-
- /* reserved */
- reserved_data = Get_Bits(7);
-
- Flush_Buffer(1); // marker bit
- copyright_number_1 = Get_Bits(20);
- Flush_Buffer(1); // marker bit
- copyright_number_2 = Get_Bits(22);
- Flush_Buffer(1); // marker bit
- copyright_number_3 = Get_Bits(22);
+ int copyright_flag;
+ int copyright_identifier;
+ int original_or_copy;
+ int copyright_number_1;
+ int copyright_number_2;
+ int copyright_number_3;
+
+ int reserved_data;
+
+ copyright_flag = Get_Bits(1);
+ copyright_identifier = Get_Bits(8);
+ original_or_copy = Get_Bits(1);
+
+ /* reserved */
+ reserved_data = Get_Bits(7);
+
+ Flush_Buffer(1); // marker bit
+ copyright_number_1 = Get_Bits(20);
+ Flush_Buffer(1); // marker bit
+ copyright_number_2 = Get_Bits(22);
+ Flush_Buffer(1); // marker bit
+ copyright_number_3 = Get_Bits(22);
}
//
// getpic
//
-static const unsigned char cc_table[12] = {
- 0, 0, 0, 0, 1, 2, 1, 2, 1, 2, 1, 2
+static const unsigned char cc_table[12] =
+{
+ 0, 0, 0, 0, 1, 2, 1, 2, 1, 2, 1, 2
};
void CMPEG2Dec::Decode_Picture(int ref, unsigned char *dst, int pitch)
{
- if (picture_structure==FRAME_PICTURE && Second_Field)
- Second_Field = 0;
+ if(picture_structure == FRAME_PICTURE && Second_Field)
+ Second_Field = 0;
- if (picture_coding_type!=B_TYPE)
- {
- pf_forward = pf_backward;
- pf_backward = pf_current;
- }
+ if(picture_coding_type != B_TYPE)
+ {
+ pf_forward = pf_backward;
+ pf_backward = pf_current;
+ }
- Update_Picture_Buffers();
+ Update_Picture_Buffers();
- picture_data();
+ picture_data();
- if (ref && (picture_structure==FRAME_PICTURE || Second_Field))
- {
- if (picture_coding_type==B_TYPE)
- assembleFrame(auxframe, pf_current, dst, pitch);
- else
- assembleFrame(forward_reference_frame, pf_forward, dst, pitch);
- }
+ if(ref && (picture_structure == FRAME_PICTURE || Second_Field))
+ {
+ if(picture_coding_type == B_TYPE)
+ assembleFrame(auxframe, pf_current, dst, pitch);
+ else
+ assembleFrame(forward_reference_frame, pf_forward, dst, pitch);
+ }
- if (picture_structure!=FRAME_PICTURE)
- Second_Field = !Second_Field;
+ if(picture_structure != FRAME_PICTURE)
+ Second_Field = !Second_Field;
}
/* reuse old picture buffers as soon as they are no longer needed */
void CMPEG2Dec::Update_Picture_Buffers()
-{
- int cc; /* color component index */
- unsigned char *tmp; /* temporary swap pointer */
-
- for (cc=0; cc<3; cc++)
- {
- /* B pictures do not need to be save for future reference */
- if (picture_coding_type==B_TYPE)
- current_frame[cc] = auxframe[cc];
- else
- {
- if (!Second_Field)
- {
- /* only update at the beginning of the coded frame */
- tmp = forward_reference_frame[cc];
-
- /* the previously decoded reference frame is stored coincident with the
- location where the backward reference frame is stored (backwards
- prediction is not needed in P pictures) */
- forward_reference_frame[cc] = backward_reference_frame[cc];
-
- /* update pointer for potential future B pictures */
- backward_reference_frame[cc] = tmp;
- }
-
- /* can erase over old backward reference frame since it is not used
- in a P picture, and since any subsequent B pictures will use the
- previously decoded I or P frame as the backward_reference_frame */
- current_frame[cc] = backward_reference_frame[cc];
- }
-
- if (picture_structure==BOTTOM_FIELD)
- current_frame[cc] += (cc==0) ? Coded_Picture_Width : Chroma_Width;
- }
+{
+ int cc; /* color component index */
+ unsigned char *tmp; /* temporary swap pointer */
+
+ for(cc = 0; cc < 3; cc++)
+ {
+ /* B pictures do not need to be save for future reference */
+ if(picture_coding_type == B_TYPE)
+ current_frame[cc] = auxframe[cc];
+ else
+ {
+ if(!Second_Field)
+ {
+ /* only update at the beginning of the coded frame */
+ tmp = forward_reference_frame[cc];
+
+ /* the previously decoded reference frame is stored coincident with the
+ location where the backward reference frame is stored (backwards
+ prediction is not needed in P pictures) */
+ forward_reference_frame[cc] = backward_reference_frame[cc];
+
+ /* update pointer for potential future B pictures */
+ backward_reference_frame[cc] = tmp;
+ }
+
+ /* can erase over old backward reference frame since it is not used
+ in a P picture, and since any subsequent B pictures will use the
+ previously decoded I or P frame as the backward_reference_frame */
+ current_frame[cc] = backward_reference_frame[cc];
+ }
+
+ if(picture_structure == BOTTOM_FIELD)
+ current_frame[cc] += (cc == 0) ? Coded_Picture_Width : Chroma_Width;
+ }
}
/* decode all macroblocks of the current picture */
/* stages described in ISO/IEC 13818-2 section 7 */
void CMPEG2Dec::picture_data()
{
- int MBAmax;
+ int MBAmax;
- /* number of macroblocks per picture */
- MBAmax = mb_width*mb_height;
+ /* number of macroblocks per picture */
+ MBAmax = mb_width * mb_height;
- if (picture_structure!=FRAME_PICTURE)
- MBAmax>>=1;
+ if(picture_structure != FRAME_PICTURE)
+ MBAmax >>= 1;
- for (;;)
- if (slice(MBAmax)<0)
- return;
+ for(;;)
+ if(slice(MBAmax) < 0)
+ return;
}
/* decode all macroblocks of the current picture */
@@ -1238,109 +1242,110 @@ void CMPEG2Dec::picture_data()
/* return -1: go to next picture */
int CMPEG2Dec::slice(int MBAmax)
{
- int MBA = 0, MBAinc =0, macroblock_type, motion_type, dct_type, ret;
- int dc_dct_pred[3], PMV[2][2][2], motion_vertical_field_select[2][2], dmvector[2];
-
- if ((ret=start_of_slice(&MBA, &MBAinc, dc_dct_pred, PMV))!=1)
- return ret;
-
- for (;;)
- {
- /* this is how we properly exit out of picture */
- if (MBA>=MBAmax) return -1; // all macroblocks decoded
-
- if (MBAinc==0)
- {
- if (!Show_Bits(23) || Fault_Flag) // next_start_code or fault
- {
-resync:
- Fault_Flag = 0;
- return 0; // trigger: go to next slice
- }
- else /* neither next_start_code nor Fault_Flag */
- {
- /* decode macroblock address increment */
- MBAinc = Get_macroblock_address_increment();
- if (Fault_Flag) goto resync;
- }
- }
-
- if (MBAinc==1) /* not skipped */
- {
- if (!decode_macroblock(&macroblock_type, &motion_type, &dct_type, PMV,
- dc_dct_pred, motion_vertical_field_select, dmvector))
- goto resync;
- }
- else /* MBAinc!=1: skipped macroblock */
- /* ISO/IEC 13818-2 section 7.6.6 */
- skipped_macroblock(dc_dct_pred, PMV, &motion_type, motion_vertical_field_select, &macroblock_type);
-
- /* ISO/IEC 13818-2 section 7.6 */
- motion_compensation(MBA, macroblock_type, motion_type, PMV,
- motion_vertical_field_select, dmvector, dct_type);
-
- /* advance to next macroblock */
- MBA++; MBAinc--;
-
- if (MBA>=MBAmax) return -1; // all macroblocks decoded
- }
+ int MBA = 0, MBAinc = 0, macroblock_type, motion_type, dct_type, ret;
+ int dc_dct_pred[3], PMV[2][2][2], motion_vertical_field_select[2][2], dmvector[2];
+
+ if((ret = start_of_slice(&MBA, &MBAinc, dc_dct_pred, PMV)) != 1)
+ return ret;
+
+ for(;;)
+ {
+ /* this is how we properly exit out of picture */
+ if(MBA >= MBAmax) return -1; // all macroblocks decoded
+
+ if(MBAinc == 0)
+ {
+ if(!Show_Bits(23) || Fault_Flag) // next_start_code or fault
+ {
+ resync:
+ Fault_Flag = 0;
+ return 0; // trigger: go to next slice
+ }
+ else /* neither next_start_code nor Fault_Flag */
+ {
+ /* decode macroblock address increment */
+ MBAinc = Get_macroblock_address_increment();
+ if(Fault_Flag) goto resync;
+ }
+ }
+
+ if(MBAinc == 1) /* not skipped */
+ {
+ if(!decode_macroblock(&macroblock_type, &motion_type, &dct_type, PMV,
+ dc_dct_pred, motion_vertical_field_select, dmvector))
+ goto resync;
+ }
+ else /* MBAinc!=1: skipped macroblock */
+ /* ISO/IEC 13818-2 section 7.6.6 */
+ skipped_macroblock(dc_dct_pred, PMV, &motion_type, motion_vertical_field_select, &macroblock_type);
+
+ /* ISO/IEC 13818-2 section 7.6 */
+ motion_compensation(MBA, macroblock_type, motion_type, PMV,
+ motion_vertical_field_select, dmvector, dct_type);
+
+ /* advance to next macroblock */
+ MBA++;
+ MBAinc--;
+
+ if(MBA >= MBAmax) return -1; // all macroblocks decoded
+ }
}
/* ISO/IEC 13818-2 section 6.3.17.1: Macroblock modes */
void CMPEG2Dec::macroblock_modes(int *pmacroblock_type, int *pmotion_type,
- int *pmotion_vector_count, int *pmv_format,
- int *pdmv, int *pmvscale, int *pdct_type)
+ int *pmotion_vector_count, int *pmv_format,
+ int *pdmv, int *pmvscale, int *pdct_type)
{
- int macroblock_type, motion_type = 0, motion_vector_count;
- int mv_format, dmv, mvscale, dct_type;
-
- /* get macroblock_type */
- macroblock_type = Get_macroblock_type();
- if (Fault_Flag) return;
-
- /* get frame/field motion type */
- if (macroblock_type & (MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD))
- {
- if (picture_structure==FRAME_PICTURE)
- motion_type = frame_pred_frame_dct ? MC_FRAME : Get_Bits(2);
- else
- motion_type = Get_Bits(2);
+ int macroblock_type, motion_type = 0, motion_vector_count;
+ int mv_format, dmv, mvscale, dct_type;
+
+ /* get macroblock_type */
+ macroblock_type = Get_macroblock_type();
+ if(Fault_Flag) return;
+
+ /* get frame/field motion type */
+ if(macroblock_type & (MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD))
+ {
+ if(picture_structure == FRAME_PICTURE)
+ motion_type = frame_pred_frame_dct ? MC_FRAME : Get_Bits(2);
+ else
+ motion_type = Get_Bits(2);
}
- else if ((macroblock_type & MACROBLOCK_INTRA) && concealment_motion_vectors)
- motion_type = (picture_structure==FRAME_PICTURE) ? MC_FRAME : MC_FIELD;
-
- /* derive motion_vector_count, mv_format and dmv, (table 6-17, 6-18) */
- if (picture_structure==FRAME_PICTURE)
- {
- motion_vector_count = (motion_type==MC_FIELD) ? 2 : 1;
- mv_format = (motion_type==MC_FRAME) ? MV_FRAME : MV_FIELD;
- }
- else
- {
- motion_vector_count = (motion_type==MC_16X8) ? 2 : 1;
- mv_format = MV_FIELD;
- }
-
- dmv = (motion_type==MC_DMV); /* dual prime */
-
- /*
- field mv predictions in frame pictures have to be scaled
- ISO/IEC 13818-2 section 7.6.3.1 Decoding the motion vectors
- */
- mvscale = (mv_format==MV_FIELD && picture_structure==FRAME_PICTURE);
-
- /* get dct_type (frame DCT / field DCT) */
- dct_type = (picture_structure==FRAME_PICTURE) && (!frame_pred_frame_dct)
- && (macroblock_type & (MACROBLOCK_PATTERN|MACROBLOCK_INTRA)) ? Get_Bits(1) : 0;
-
- /* return values */
- *pmacroblock_type = macroblock_type;
- *pmotion_type = motion_type;
- *pmotion_vector_count = motion_vector_count;
- *pmv_format = mv_format;
- *pdmv = dmv;
- *pmvscale = mvscale;
- *pdct_type = dct_type;
+ else if((macroblock_type & MACROBLOCK_INTRA) && concealment_motion_vectors)
+ motion_type = (picture_structure == FRAME_PICTURE) ? MC_FRAME : MC_FIELD;
+
+ /* derive motion_vector_count, mv_format and dmv, (table 6-17, 6-18) */
+ if(picture_structure == FRAME_PICTURE)
+ {
+ motion_vector_count = (motion_type == MC_FIELD) ? 2 : 1;
+ mv_format = (motion_type == MC_FRAME) ? MV_FRAME : MV_FIELD;
+ }
+ else
+ {
+ motion_vector_count = (motion_type == MC_16X8) ? 2 : 1;
+ mv_format = MV_FIELD;
+ }
+
+ dmv = (motion_type == MC_DMV); /* dual prime */
+
+ /*
+ field mv predictions in frame pictures have to be scaled
+ ISO/IEC 13818-2 section 7.6.3.1 Decoding the motion vectors
+ */
+ mvscale = (mv_format == MV_FIELD && picture_structure == FRAME_PICTURE);
+
+ /* get dct_type (frame DCT / field DCT) */
+ dct_type = (picture_structure == FRAME_PICTURE) && (!frame_pred_frame_dct)
+ && (macroblock_type & (MACROBLOCK_PATTERN | MACROBLOCK_INTRA)) ? Get_Bits(1) : 0;
+
+ /* return values */
+ *pmacroblock_type = macroblock_type;
+ *pmotion_type = motion_type;
+ *pmotion_vector_count = motion_vector_count;
+ *pmv_format = mv_format;
+ *pdmv = dmv;
+ *pmvscale = mvscale;
+ *pdct_type = dct_type;
}
/* move/add 8x8-Block from block[comp] to backward_reference_frame */
@@ -1352,791 +1357,792 @@ void CMPEG2Dec::macroblock_modes(int *pmacroblock_type, int *pmotion_type,
*/
void CMPEG2Dec::Add_Block(int count, int bx, int by, int dct_type, int addflag)
{
- static const __int64 mmmask_128 = 0x0080008000800080;
-
- int comp, cc, iincr, bxh, byh;
- unsigned char *rfp;
- short *Block_Ptr;
-
- for (comp=0; comp<count; comp++)
- {
- Block_Ptr = block[comp];
- cc = cc_table[comp];
-
- bxh = bx; byh = by;
-
- if (cc==0)
- {
- if (picture_structure==FRAME_PICTURE)
- {
- if (dct_type)
- {
- rfp = current_frame[0] + Coded_Picture_Width*(by+((comp&2)>>1)) + bx + ((comp&1)<<3);
- iincr = Coded_Picture_Width<<1;
- }
- else
- {
- rfp = current_frame[0] + Coded_Picture_Width*(by+((comp&2)<<2)) + bx + ((comp&1)<<3);
- iincr = Coded_Picture_Width;
- }
- }
- else
- {
- rfp = current_frame[0] + (Coded_Picture_Width<<1)*(by+((comp&2)<<2)) + bx + ((comp&1)<<3);
- iincr = Coded_Picture_Width<<1;
- }
- }
- else
- {
- if (chroma_format!=CHROMA444)
- bxh >>= 1;
- if (chroma_format==CHROMA420)
- byh >>= 1;
-
- if (picture_structure==FRAME_PICTURE)
- {
- if (dct_type && chroma_format!=CHROMA420)
- {
- /* field DCT coding */
- rfp = current_frame[cc] + Chroma_Width*(byh+((comp&2)>>1)) + bxh + (comp&8);
- iincr = Chroma_Width<<1;
- }
- else
- {
- /* frame DCT coding */
- rfp = current_frame[cc] + Chroma_Width*(byh+((comp&2)<<2)) + bxh + (comp&8);
- iincr = Chroma_Width;
- }
- }
- else
- {
- /* field picture */
- rfp = current_frame[cc] + (Chroma_Width<<1)*(byh+((comp&2)<<2)) + bxh + (comp&8);
- iincr = Chroma_Width<<1;
- }
- }
-
- if (addflag)
- {
- __asm
- {
- pxor mm0, mm0
- mov eax, [rfp]
- mov ebx, [Block_Ptr]
- mov edi, 8
-addon:
- movq mm2, [ebx+8]
-
- movq mm3, [eax]
- movq mm4, mm3
-
- movq mm1, [ebx]
- punpckhbw mm3, mm0
-
- paddsw mm3, mm2
- packuswb mm3, mm0
-
- punpcklbw mm4, mm0
- psllq mm3, 32
-
- paddsw mm4, mm1
- packuswb mm4, mm0
-
- por mm3, mm4
- add ebx, 16
-
- dec edi
- movq [eax], mm3
-
- add eax, [iincr]
- cmp edi, 0x00
- jg addon
- }
- }
- else
- {
- __asm
- {
- mov eax, [rfp]
- mov ebx, [Block_Ptr]
- mov edi, 8
-
- pxor mm0, mm0
- movq mm7, [mmmask_128]
-addoff:
- movq mm3, [ebx+8]
- movq mm4, [ebx]
-
- paddsw mm3, mm7
- paddsw mm4, mm7
-
- packuswb mm3, mm0
- packuswb mm4, mm0
-
- psllq mm3, 32
- por mm3, mm4
-
- add ebx, 16
- dec edi
-
- movq [eax], mm3
-
- add eax, [iincr]
- cmp edi, 0x00
- jg addoff
- }
- }
- }
+ static const __int64 mmmask_128 = 0x0080008000800080;
+
+ int comp, cc, iincr, bxh, byh;
+ unsigned char *rfp;
+ short *Block_Ptr;
+
+ for(comp = 0; comp < count; comp++)
+ {
+ Block_Ptr = block[comp];
+ cc = cc_table[comp];
+
+ bxh = bx;
+ byh = by;
+
+ if(cc == 0)
+ {
+ if(picture_structure == FRAME_PICTURE)
+ {
+ if(dct_type)
+ {
+ rfp = current_frame[0] + Coded_Picture_Width * (by + ((comp & 2) >> 1)) + bx + ((comp & 1) << 3);
+ iincr = Coded_Picture_Width << 1;
+ }
+ else
+ {
+ rfp = current_frame[0] + Coded_Picture_Width * (by + ((comp & 2) << 2)) + bx + ((comp & 1) << 3);
+ iincr = Coded_Picture_Width;
+ }
+ }
+ else
+ {
+ rfp = current_frame[0] + (Coded_Picture_Width << 1) * (by + ((comp & 2) << 2)) + bx + ((comp & 1) << 3);
+ iincr = Coded_Picture_Width << 1;
+ }
+ }
+ else
+ {
+ if(chroma_format != CHROMA444)
+ bxh >>= 1;
+ if(chroma_format == CHROMA420)
+ byh >>= 1;
+
+ if(picture_structure == FRAME_PICTURE)
+ {
+ if(dct_type && chroma_format != CHROMA420)
+ {
+ /* field DCT coding */
+ rfp = current_frame[cc] + Chroma_Width * (byh + ((comp & 2) >> 1)) + bxh + (comp & 8);
+ iincr = Chroma_Width << 1;
+ }
+ else
+ {
+ /* frame DCT coding */
+ rfp = current_frame[cc] + Chroma_Width * (byh + ((comp & 2) << 2)) + bxh + (comp & 8);
+ iincr = Chroma_Width;
+ }
+ }
+ else
+ {
+ /* field picture */
+ rfp = current_frame[cc] + (Chroma_Width << 1) * (byh + ((comp & 2) << 2)) + bxh + (comp & 8);
+ iincr = Chroma_Width << 1;
+ }
+ }
+
+ if(addflag)
+ {
+ __asm
+ {
+ pxor mm0, mm0
+ mov eax, [rfp]
+ mov ebx, [Block_Ptr]
+ mov edi, 8
+ addon:
+ movq mm2, [ebx+8]
+
+ movq mm3, [eax]
+ movq mm4, mm3
+
+ movq mm1, [ebx]
+ punpckhbw mm3, mm0
+
+ paddsw mm3, mm2
+ packuswb mm3, mm0
+
+ punpcklbw mm4, mm0
+ psllq mm3, 32
+
+ paddsw mm4, mm1
+ packuswb mm4, mm0
+
+ por mm3, mm4
+ add ebx, 16
+
+ dec edi
+ movq [eax], mm3
+
+ add eax, [iincr]
+ cmp edi, 0x00
+ jg addon
+ }
+ }
+ else
+ {
+ __asm
+ {
+ mov eax, [rfp]
+ mov ebx, [Block_Ptr]
+ mov edi, 8
+
+ pxor mm0, mm0
+ movq mm7, [mmmask_128]
+ addoff:
+ movq mm3, [ebx+8]
+ movq mm4, [ebx]
+
+ paddsw mm3, mm7
+ paddsw mm4, mm7
+
+ packuswb mm3, mm0
+ packuswb mm4, mm0
+
+ psllq mm3, 32
+ por mm3, mm4
+
+ add ebx, 16
+ dec edi
+
+ movq [eax], mm3
+
+ add eax, [iincr]
+ cmp edi, 0x00
+ jg addoff
+ }
+ }
+ }
}
/* set scratch pad macroblock to zero */
void CMPEG2Dec::Clear_Block(int count)
{
- int comp;
- short *Block_Ptr;
-
- for (comp=0; comp<count; comp++)
- {
- Block_Ptr = block[comp];
-
- __asm
- {
- mov eax, [Block_Ptr];
- pxor mm0, mm0;
- movq [eax+0 ], mm0;
- movq [eax+8 ], mm0;
- movq [eax+16], mm0;
- movq [eax+24], mm0;
- movq [eax+32], mm0;
- movq [eax+40], mm0;
- movq [eax+48], mm0;
- movq [eax+56], mm0;
- movq [eax+64], mm0;
- movq [eax+72], mm0;
- movq [eax+80], mm0;
- movq [eax+88], mm0;
- movq [eax+96], mm0;
- movq [eax+104],mm0;
- movq [eax+112],mm0;
- movq [eax+120],mm0;
- }
- }
+ int comp;
+ short *Block_Ptr;
+
+ for(comp = 0; comp < count; comp++)
+ {
+ Block_Ptr = block[comp];
+
+ __asm
+ {
+ mov eax, [Block_Ptr];
+ pxor mm0, mm0;
+ movq [eax+0 ], mm0;
+ movq [eax+8 ], mm0;
+ movq [eax+16], mm0;
+ movq [eax+24], mm0;
+ movq [eax+32], mm0;
+ movq [eax+40], mm0;
+ movq [eax+48], mm0;
+ movq [eax+56], mm0;
+ movq [eax+64], mm0;
+ movq [eax+72], mm0;
+ movq [eax+80], mm0;
+ movq [eax+88], mm0;
+ movq [eax+96], mm0;
+ movq [eax+104], mm0;
+ movq [eax+112], mm0;
+ movq [eax+120], mm0;
+ }
+ }
}
/* ISO/IEC 13818-2 section 7.6 */
-void CMPEG2Dec::motion_compensation(int MBA, int macroblock_type, int motion_type,
- int PMV[2][2][2], int motion_vertical_field_select[2][2],
- int dmvector[2], int dct_type)
+void CMPEG2Dec::motion_compensation(int MBA, int macroblock_type, int motion_type,
+ int PMV[2][2][2], int motion_vertical_field_select[2][2],
+ int dmvector[2], int dct_type)
{
- int bx, by;
- int comp;
-
- /* derive current macroblock position within picture */
- /* ISO/IEC 13818-2 section 6.3.1.6 and 6.3.1.7 */
- bx = 16*(MBA%mb_width);
- by = 16*(MBA/mb_width);
-
- /* motion compensation */
- if (!(macroblock_type & MACROBLOCK_INTRA))
- form_predictions(bx, by, macroblock_type, motion_type, PMV,
- motion_vertical_field_select, dmvector);
-
- switch (IDCT_Flag)
- {
- case IDCT_MMX:
- for (comp=0; comp<block_count; comp++)
- MMX_IDCT(block[comp]);
- break;
-
- case IDCT_SSEMMX:
- for (comp=0; comp<block_count; comp++)
- SSEMMX_IDCT(block[comp]);
- break;
-
- case IDCT_FPU:
- __asm emms;
- for (comp=0; comp<block_count; comp++)
- FPU_IDCT(block[comp]);
- break;
-
- case IDCT_REF:
- __asm emms;
- for (comp=0; comp<block_count; comp++)
- REF_IDCT(block[comp]);
- break;
- }
-
- Add_Block(block_count, bx, by, dct_type, (macroblock_type & MACROBLOCK_INTRA)==0);
+ int bx, by;
+ int comp;
+
+ /* derive current macroblock position within picture */
+ /* ISO/IEC 13818-2 section 6.3.1.6 and 6.3.1.7 */
+ bx = 16 * (MBA % mb_width);
+ by = 16 * (MBA / mb_width);
+
+ /* motion compensation */
+ if(!(macroblock_type & MACROBLOCK_INTRA))
+ form_predictions(bx, by, macroblock_type, motion_type, PMV,
+ motion_vertical_field_select, dmvector);
+
+ switch(IDCT_Flag)
+ {
+ case IDCT_MMX:
+ for(comp = 0; comp < block_count; comp++)
+ MMX_IDCT(block[comp]);
+ break;
+
+ case IDCT_SSEMMX:
+ for(comp = 0; comp < block_count; comp++)
+ SSEMMX_IDCT(block[comp]);
+ break;
+
+ case IDCT_FPU:
+ __asm emms;
+ for(comp = 0; comp < block_count; comp++)
+ FPU_IDCT(block[comp]);
+ break;
+
+ case IDCT_REF:
+ __asm emms;
+ for(comp = 0; comp < block_count; comp++)
+ REF_IDCT(block[comp]);
+ break;
+ }
+
+ Add_Block(block_count, bx, by, dct_type, (macroblock_type & MACROBLOCK_INTRA) == 0);
}
/* ISO/IEC 13818-2 section 7.6.6 */
-void CMPEG2Dec::skipped_macroblock(int dc_dct_pred[3], int PMV[2][2][2], int *motion_type,
- int motion_vertical_field_select[2][2], int *macroblock_type)
+void CMPEG2Dec::skipped_macroblock(int dc_dct_pred[3], int PMV[2][2][2], int *motion_type,
+ int motion_vertical_field_select[2][2], int *macroblock_type)
{
- Clear_Block(block_count);
-
- /* reset intra_dc predictors */
- /* ISO/IEC 13818-2 section 7.2.1: DC coefficients in intra blocks */
- dc_dct_pred[0]=dc_dct_pred[1]=dc_dct_pred[2]=0;
-
- /* reset motion vector predictors */
- /* ISO/IEC 13818-2 section 7.6.3.4: Resetting motion vector predictors */
- if (picture_coding_type==P_TYPE)
- PMV[0][0][0]=PMV[0][0][1]=PMV[1][0][0]=PMV[1][0][1]=0;
-
- /* derive motion_type */
- if (picture_structure==FRAME_PICTURE)
- *motion_type = MC_FRAME;
- else
- {
- *motion_type = MC_FIELD;
- motion_vertical_field_select[0][0] = motion_vertical_field_select[0][1] =
- (picture_structure==BOTTOM_FIELD);
- }
-
- /* clear MACROBLOCK_INTRA */
- *macroblock_type&= ~MACROBLOCK_INTRA;
+ Clear_Block(block_count);
+
+ /* reset intra_dc predictors */
+ /* ISO/IEC 13818-2 section 7.2.1: DC coefficients in intra blocks */
+ dc_dct_pred[0] = dc_dct_pred[1] = dc_dct_pred[2] = 0;
+
+ /* reset motion vector predictors */
+ /* ISO/IEC 13818-2 section 7.6.3.4: Resetting motion vector predictors */
+ if(picture_coding_type == P_TYPE)
+ PMV[0][0][0] = PMV[0][0][1] = PMV[1][0][0] = PMV[1][0][1] = 0;
+
+ /* derive motion_type */
+ if(picture_structure == FRAME_PICTURE)
+ *motion_type = MC_FRAME;
+ else
+ {
+ *motion_type = MC_FIELD;
+ motion_vertical_field_select[0][0] = motion_vertical_field_select[0][1] =
+ (picture_structure == BOTTOM_FIELD);
+ }
+
+ /* clear MACROBLOCK_INTRA */
+ *macroblock_type &= ~MACROBLOCK_INTRA;
}
/* return==-1 means go to next picture */
/* the expression "start of slice" is used throughout the normative
body of the MPEG specification */
int CMPEG2Dec::start_of_slice(int *MBA, int *MBAinc,
- int dc_dct_pred[3], int PMV[2][2][2])
+ int dc_dct_pred[3], int PMV[2][2][2])
{
- unsigned int code;
- int slice_vert_pos_ext;
-
- next_start_code();
- code = Get_Bits(32);
-
- if (code<SLICE_START_CODE_MIN || code>SLICE_START_CODE_MAX)
- {
- // only slice headers are allowed in picture_data
- Fault_Flag = 10;
- return -1;
- }
-
- /* decode slice header (may change quantizer_scale) */
- slice_vert_pos_ext = slice_header();
-
- /* decode macroblock address increment */
- *MBAinc = Get_macroblock_address_increment();
- if (Fault_Flag) return -1;
-
- /* set current location */
- /* NOTE: the arithmetic used to derive macroblock_address below is
- equivalent to ISO/IEC 13818-2 section 6.3.17: Macroblock */
- *MBA = ((slice_vert_pos_ext<<7) + (code&255) - 1)*mb_width + *MBAinc - 1;
- *MBAinc = 1; // first macroblock in slice: not skipped
-
- /* reset all DC coefficient and motion vector predictors */
- /* ISO/IEC 13818-2 section 7.2.1: DC coefficients in intra blocks */
- dc_dct_pred[0]=dc_dct_pred[1]=dc_dct_pred[2]=0;
-
- /* ISO/IEC 13818-2 section 7.6.3.4: Resetting motion vector predictors */
- PMV[0][0][0]=PMV[0][0][1]=PMV[1][0][0]=PMV[1][0][1]=0;
- PMV[0][1][0]=PMV[0][1][1]=PMV[1][1][0]=PMV[1][1][1]=0;
-
- /* successfull: trigger decode macroblocks in slice */
- return 1;
+ unsigned int code;
+ int slice_vert_pos_ext;
+
+ next_start_code();
+ code = Get_Bits(32);
+
+ if(code < SLICE_START_CODE_MIN || code > SLICE_START_CODE_MAX)
+ {
+ // only slice headers are allowed in picture_data
+ Fault_Flag = 10;
+ return -1;
+ }
+
+ /* decode slice header (may change quantizer_scale) */
+ slice_vert_pos_ext = slice_header();
+
+ /* decode macroblock address increment */
+ *MBAinc = Get_macroblock_address_increment();
+ if(Fault_Flag) return -1;
+
+ /* set current location */
+ /* NOTE: the arithmetic used to derive macroblock_address below is
+ equivalent to ISO/IEC 13818-2 section 6.3.17: Macroblock */
+ *MBA = ((slice_vert_pos_ext << 7) + (code & 255) - 1) * mb_width + *MBAinc - 1;
+ *MBAinc = 1; // first macroblock in slice: not skipped
+
+ /* reset all DC coefficient and motion vector predictors */
+ /* ISO/IEC 13818-2 section 7.2.1: DC coefficients in intra blocks */
+ dc_dct_pred[0] = dc_dct_pred[1] = dc_dct_pred[2] = 0;
+
+ /* ISO/IEC 13818-2 section 7.6.3.4: Resetting motion vector predictors */
+ PMV[0][0][0] = PMV[0][0][1] = PMV[1][0][0] = PMV[1][0][1] = 0;
+ PMV[0][1][0] = PMV[0][1][1] = PMV[1][1][0] = PMV[1][1][1] = 0;
+
+ /* successfull: trigger decode macroblocks in slice */
+ return 1;
}
/* ISO/IEC 13818-2 sections 7.2 through 7.5 */
int CMPEG2Dec::decode_macroblock(int *macroblock_type, int *motion_type, int *dct_type,
- int PMV[2][2][2], int dc_dct_pred[3],
- int motion_vertical_field_select[2][2], int dmvector[2])
+ int PMV[2][2][2], int dc_dct_pred[3],
+ int motion_vertical_field_select[2][2], int dmvector[2])
{
- int quantizer_scale_code, comp, motion_vector_count, mv_format;
- int dmv, mvscale, coded_block_pattern;
-
- /* ISO/IEC 13818-2 section 6.3.17.1: Macroblock modes */
- macroblock_modes(macroblock_type, motion_type, &motion_vector_count, &mv_format,
- &dmv, &mvscale, dct_type);
- if (Fault_Flag) return 0; // trigger: go to next slice
-
- if (*macroblock_type & MACROBLOCK_QUANT)
- {
- quantizer_scale_code = Get_Bits(5);
-
- /* ISO/IEC 13818-2 section 7.4.2.2: Quantizer scale factor */
- quantizer_scale = q_scale_type ?
- Non_Linear_quantizer_scale[quantizer_scale_code] : (quantizer_scale_code << 1);
- }
-
- /* ISO/IEC 13818-2 section 6.3.17.2: Motion vectors */
- /* decode forward motion vectors */
- if ((*macroblock_type & MACROBLOCK_MOTION_FORWARD)
- || ((*macroblock_type & MACROBLOCK_INTRA) && concealment_motion_vectors))
- motion_vectors(PMV, dmvector, motion_vertical_field_select, 0,
- motion_vector_count, mv_format, f_code[0][0]-1, f_code[0][1]-1, dmv, mvscale);
- if (Fault_Flag) return 0; // trigger: go to next slice
-
- /* decode backward motion vectors */
- if (*macroblock_type & MACROBLOCK_MOTION_BACKWARD)
- motion_vectors(PMV, dmvector, motion_vertical_field_select, 1,
- motion_vector_count,mv_format, f_code[1][0]-1, f_code[1][1]-1, 0, mvscale);
- if (Fault_Flag) return 0; // trigger: go to next slice
-
- if ((*macroblock_type & MACROBLOCK_INTRA) && concealment_motion_vectors)
- Flush_Buffer(1); // marker bit
-
- /* macroblock_pattern */
- /* ISO/IEC 13818-2 section 6.3.17.4: Coded block pattern */
- if (*macroblock_type & MACROBLOCK_PATTERN)
- {
- coded_block_pattern = Get_coded_block_pattern();
-
- if (chroma_format==CHROMA422)
- coded_block_pattern = (coded_block_pattern<<2) | Get_Bits(2);
- else if (chroma_format==CHROMA444)
- coded_block_pattern = (coded_block_pattern<<6) | Get_Bits(6);
- }
- else
- coded_block_pattern = (*macroblock_type & MACROBLOCK_INTRA) ? (1<<block_count)-1 : 0;
-
- if (Fault_Flag) return 0; // trigger: go to next slice
-
- Clear_Block(block_count);
-
- /* decode blocks */
- for (comp=0; comp<block_count; comp++)
- {
- if (coded_block_pattern & (1<<(block_count-1-comp)))
- {
- if (*macroblock_type & MACROBLOCK_INTRA)
- Decode_MPEG2_Intra_Block(comp, dc_dct_pred);
- else
- Decode_MPEG2_Non_Intra_Block(comp);
- if (Fault_Flag) return 0; // trigger: go to next slice
- }
- }
-
- /* reset intra_dc predictors */
- /* ISO/IEC 13818-2 section 7.2.1: DC coefficients in intra blocks */
- if (!(*macroblock_type & MACROBLOCK_INTRA))
- dc_dct_pred[0]=dc_dct_pred[1]=dc_dct_pred[2]=0;
-
- /* reset motion vector predictors */
- if ((*macroblock_type & MACROBLOCK_INTRA) && !concealment_motion_vectors)
- {
- /* intra mb without concealment motion vectors */
- /* ISO/IEC 13818-2 section 7.6.3.4: Resetting motion vector predictors */
- PMV[0][0][0]=PMV[0][0][1]=PMV[1][0][0]=PMV[1][0][1]=0;
- PMV[0][1][0]=PMV[0][1][1]=PMV[1][1][0]=PMV[1][1][1]=0;
- }
-
- /* special "No_MC" macroblock_type case */
- /* ISO/IEC 13818-2 section 7.6.3.5: Prediction in P pictures */
- if ((picture_coding_type==P_TYPE)
- && !(*macroblock_type & (MACROBLOCK_MOTION_FORWARD|MACROBLOCK_INTRA)))
- {
- /* non-intra mb without forward mv in a P picture */
- /* ISO/IEC 13818-2 section 7.6.3.4: Resetting motion vector predictors */
- PMV[0][0][0]=PMV[0][0][1]=PMV[1][0][0]=PMV[1][0][1]=0;
-
- /* derive motion_type */
- /* ISO/IEC 13818-2 section 6.3.17.1: Macroblock modes, frame_motion_type */
- if (picture_structure==FRAME_PICTURE)
- *motion_type = MC_FRAME;
- else
- {
- *motion_type = MC_FIELD;
- motion_vertical_field_select[0][0] = (picture_structure==BOTTOM_FIELD);
- }
- }
- /* successfully decoded macroblock */
- return 1 ;
+ int quantizer_scale_code, comp, motion_vector_count, mv_format;
+ int dmv, mvscale, coded_block_pattern;
+
+ /* ISO/IEC 13818-2 section 6.3.17.1: Macroblock modes */
+ macroblock_modes(macroblock_type, motion_type, &motion_vector_count, &mv_format,
+ &dmv, &mvscale, dct_type);
+ if(Fault_Flag) return 0; // trigger: go to next slice
+
+ if(*macroblock_type & MACROBLOCK_QUANT)
+ {
+ quantizer_scale_code = Get_Bits(5);
+
+ /* ISO/IEC 13818-2 section 7.4.2.2: Quantizer scale factor */
+ quantizer_scale = q_scale_type ?
+ Non_Linear_quantizer_scale[quantizer_scale_code] : (quantizer_scale_code << 1);
+ }
+
+ /* ISO/IEC 13818-2 section 6.3.17.2: Motion vectors */
+ /* decode forward motion vectors */
+ if((*macroblock_type & MACROBLOCK_MOTION_FORWARD)
+ || ((*macroblock_type & MACROBLOCK_INTRA) && concealment_motion_vectors))
+ motion_vectors(PMV, dmvector, motion_vertical_field_select, 0,
+ motion_vector_count, mv_format, f_code[0][0] - 1, f_code[0][1] - 1, dmv, mvscale);
+ if(Fault_Flag) return 0; // trigger: go to next slice
+
+ /* decode backward motion vectors */
+ if(*macroblock_type & MACROBLOCK_MOTION_BACKWARD)
+ motion_vectors(PMV, dmvector, motion_vertical_field_select, 1,
+ motion_vector_count, mv_format, f_code[1][0] - 1, f_code[1][1] - 1, 0, mvscale);
+ if(Fault_Flag) return 0; // trigger: go to next slice
+
+ if((*macroblock_type & MACROBLOCK_INTRA) && concealment_motion_vectors)
+ Flush_Buffer(1); // marker bit
+
+ /* macroblock_pattern */
+ /* ISO/IEC 13818-2 section 6.3.17.4: Coded block pattern */
+ if(*macroblock_type & MACROBLOCK_PATTERN)
+ {
+ coded_block_pattern = Get_coded_block_pattern();
+
+ if(chroma_format == CHROMA422)
+ coded_block_pattern = (coded_block_pattern << 2) | Get_Bits(2);
+ else if(chroma_format == CHROMA444)
+ coded_block_pattern = (coded_block_pattern << 6) | Get_Bits(6);
+ }
+ else
+ coded_block_pattern = (*macroblock_type & MACROBLOCK_INTRA) ? (1 << block_count) - 1 : 0;
+
+ if(Fault_Flag) return 0; // trigger: go to next slice
+
+ Clear_Block(block_count);
+
+ /* decode blocks */
+ for(comp = 0; comp < block_count; comp++)
+ {
+ if(coded_block_pattern & (1 << (block_count - 1 - comp)))
+ {
+ if(*macroblock_type & MACROBLOCK_INTRA)
+ Decode_MPEG2_Intra_Block(comp, dc_dct_pred);
+ else
+ Decode_MPEG2_Non_Intra_Block(comp);
+ if(Fault_Flag) return 0; // trigger: go to next slice
+ }
+ }
+
+ /* reset intra_dc predictors */
+ /* ISO/IEC 13818-2 section 7.2.1: DC coefficients in intra blocks */
+ if(!(*macroblock_type & MACROBLOCK_INTRA))
+ dc_dct_pred[0] = dc_dct_pred[1] = dc_dct_pred[2] = 0;
+
+ /* reset motion vector predictors */
+ if((*macroblock_type & MACROBLOCK_INTRA) && !concealment_motion_vectors)
+ {
+ /* intra mb without concealment motion vectors */
+ /* ISO/IEC 13818-2 section 7.6.3.4: Resetting motion vector predictors */
+ PMV[0][0][0] = PMV[0][0][1] = PMV[1][0][0] = PMV[1][0][1] = 0;
+ PMV[0][1][0] = PMV[0][1][1] = PMV[1][1][0] = PMV[1][1][1] = 0;
+ }
+
+ /* special "No_MC" macroblock_type case */
+ /* ISO/IEC 13818-2 section 7.6.3.5: Prediction in P pictures */
+ if((picture_coding_type == P_TYPE)
+ && !(*macroblock_type & (MACROBLOCK_MOTION_FORWARD | MACROBLOCK_INTRA)))
+ {
+ /* non-intra mb without forward mv in a P picture */
+ /* ISO/IEC 13818-2 section 7.6.3.4: Resetting motion vector predictors */
+ PMV[0][0][0] = PMV[0][0][1] = PMV[1][0][0] = PMV[1][0][1] = 0;
+
+ /* derive motion_type */
+ /* ISO/IEC 13818-2 section 6.3.17.1: Macroblock modes, frame_motion_type */
+ if(picture_structure == FRAME_PICTURE)
+ *motion_type = MC_FRAME;
+ else
+ {
+ *motion_type = MC_FIELD;
+ motion_vertical_field_select[0][0] = (picture_structure == BOTTOM_FIELD);
+ }
+ }
+ /* successfully decoded macroblock */
+ return 1 ;
}
/* decode one intra coded MPEG-2 block */
void CMPEG2Dec::Decode_MPEG2_Intra_Block(int comp, int dc_dct_pred[])
{
- int val, i, j, sign, *qmat;
- unsigned int code;
- DCTtab *tab;
- short *bp;
-
- bp = block[comp];
- qmat = (comp<4 || chroma_format==CHROMA420)
- ? intra_quantizer_matrix : chroma_intra_quantizer_matrix;
-
- /* ISO/IEC 13818-2 section 7.2.1: decode DC coefficients */
- switch (cc_table[comp])
- {
- case 0:
- val = (dc_dct_pred[0]+= Get_Luma_DC_dct_diff());
- break;
-
- case 1:
- val = (dc_dct_pred[1]+= Get_Chroma_DC_dct_diff());
- break;
-
- case 2:
- val = (dc_dct_pred[2]+= Get_Chroma_DC_dct_diff());
- break;
- }
-
- bp[0] = val << (3-intra_dc_precision);
-
- /* decode AC coefficients */
- for (i=1; ; i++)
- {
- code = Show_Bits(16);
-
- if (code>=16384 && !intra_vlc_format)
- tab = &DCTtabnext[(code>>12)-4];
- else if (code>=1024)
- {
- if (intra_vlc_format)
- tab = &DCTtab0a[(code>>8)-4];
- else
- tab = &DCTtab0[(code>>8)-4];
- }
- else if (code>=512)
- {
- if (intra_vlc_format)
- tab = &DCTtab1a[(code>>6)-8];
- else
- tab = &DCTtab1[(code>>6)-8];
- }
- else if (code>=256)
- tab = &DCTtab2[(code>>4)-16];
- else if (code>=128)
- tab = &DCTtab3[(code>>3)-16];
- else if (code>=64)
- tab = &DCTtab4[(code>>2)-16];
- else if (code>=32)
- tab = &DCTtab5[(code>>1)-16];
- else if (code>=16)
- tab = &DCTtab6[code-16];
- else
- {
- Fault_Flag = 1;
- return;
- }
-
- Flush_Buffer(tab->len);
-
- if (tab->run<64)
- {
- i+= tab->run;
- val = tab->level;
- sign = Get_Bits(1);
- }
- else if (tab->run==64) /* end_of_block */
- return;
- else /* escape */
- {
- i+= Get_Bits(6);
- val = Get_Bits(12);
-
- if (sign = (val>=2048))
- val = 4096 - val;
- }
-
- j = scan[alternate_scan][i];
-
- val = (val * quantizer_scale * qmat[j]) >> 4;
- bp[j] = sign ? -val : val;
- }
+ int val, i, j, sign, *qmat;
+ unsigned int code;
+ DCTtab *tab;
+ short *bp;
+
+ bp = block[comp];
+ qmat = (comp < 4 || chroma_format == CHROMA420)
+ ? intra_quantizer_matrix : chroma_intra_quantizer_matrix;
+
+ /* ISO/IEC 13818-2 section 7.2.1: decode DC coefficients */
+ switch(cc_table[comp])
+ {
+ case 0:
+ val = (dc_dct_pred[0] += Get_Luma_DC_dct_diff());
+ break;
+
+ case 1:
+ val = (dc_dct_pred[1] += Get_Chroma_DC_dct_diff());
+ break;
+
+ case 2:
+ val = (dc_dct_pred[2] += Get_Chroma_DC_dct_diff());
+ break;
+ }
+
+ bp[0] = val << (3 - intra_dc_precision);
+
+ /* decode AC coefficients */
+ for(i = 1; ; i++)
+ {
+ code = Show_Bits(16);
+
+ if(code >= 16384 && !intra_vlc_format)
+ tab = &DCTtabnext[(code>>12)-4];
+ else if(code >= 1024)
+ {
+ if(intra_vlc_format)
+ tab = &DCTtab0a[(code>>8)-4];
+ else
+ tab = &DCTtab0[(code>>8)-4];
+ }
+ else if(code >= 512)
+ {
+ if(intra_vlc_format)
+ tab = &DCTtab1a[(code>>6)-8];
+ else
+ tab = &DCTtab1[(code>>6)-8];
+ }
+ else if(code >= 256)
+ tab = &DCTtab2[(code>>4)-16];
+ else if(code >= 128)
+ tab = &DCTtab3[(code>>3)-16];
+ else if(code >= 64)
+ tab = &DCTtab4[(code>>2)-16];
+ else if(code >= 32)
+ tab = &DCTtab5[(code>>1)-16];
+ else if(code >= 16)
+ tab = &DCTtab6[code-16];
+ else
+ {
+ Fault_Flag = 1;
+ return;
+ }
+
+ Flush_Buffer(tab->len);
+
+ if(tab->run < 64)
+ {
+ i += tab->run;
+ val = tab->level;
+ sign = Get_Bits(1);
+ }
+ else if(tab->run == 64) /* end_of_block */
+ return;
+ else /* escape */
+ {
+ i += Get_Bits(6);
+ val = Get_Bits(12);
+
+ if(sign = (val >= 2048))
+ val = 4096 - val;
+ }
+
+ j = scan[alternate_scan][i];
+
+ val = (val * quantizer_scale * qmat[j]) >> 4;
+ bp[j] = sign ? -val : val;
+ }
}
/* decode one non-intra coded MPEG-2 block */
void CMPEG2Dec::Decode_MPEG2_Non_Intra_Block(int comp)
{
- int val, i, j, sign, *qmat;
- unsigned int code;
- DCTtab *tab;
- short *bp;
-
- bp = block[comp];
- qmat = (comp<4 || chroma_format==CHROMA420)
- ? non_intra_quantizer_matrix : chroma_non_intra_quantizer_matrix;
-
- /* decode AC coefficients */
- for (i=0; ; i++)
- {
- code = Show_Bits(16);
-
- if (code>=16384)
- {
- if (i==0)
- tab = &DCTtabfirst[(code>>12)-4];
- else
- tab = &DCTtabnext[(code>>12)-4];
- }
- else if (code>=1024)
- tab = &DCTtab0[(code>>8)-4];
- else if (code>=512)
- tab = &DCTtab1[(code>>6)-8];
- else if (code>=256)
- tab = &DCTtab2[(code>>4)-16];
- else if (code>=128)
- tab = &DCTtab3[(code>>3)-16];
- else if (code>=64)
- tab = &DCTtab4[(code>>2)-16];
- else if (code>=32)
- tab = &DCTtab5[(code>>1)-16];
- else if (code>=16)
- tab = &DCTtab6[code-16];
- else
- {
- Fault_Flag = 1;
- return;
- }
-
- Flush_Buffer(tab->len);
-
- if (tab->run<64)
- {
- i+= tab->run;
- val = tab->level;
- sign = Get_Bits(1);
- }
- else if (tab->run==64) /* end_of_block */
- return;
- else /* escape */
- {
- i+= Get_Bits(6);
- val = Get_Bits(12);
-
- if (sign = (val>=2048))
- val = 4096 - val;
- }
-
- j = scan[alternate_scan][i];
-
- val = (((val<<1)+1) * quantizer_scale * qmat[j]) >> 5;
- bp[j] = sign ? -val : val;
- }
+ int val, i, j, sign, *qmat;
+ unsigned int code;
+ DCTtab *tab;
+ short *bp;
+
+ bp = block[comp];
+ qmat = (comp < 4 || chroma_format == CHROMA420)
+ ? non_intra_quantizer_matrix : chroma_non_intra_quantizer_matrix;
+
+ /* decode AC coefficients */
+ for(i = 0; ; i++)
+ {
+ code = Show_Bits(16);
+
+ if(code >= 16384)
+ {
+ if(i == 0)
+ tab = &DCTtabfirst[(code>>12)-4];
+ else
+ tab = &DCTtabnext[(code>>12)-4];
+ }
+ else if(code >= 1024)
+ tab = &DCTtab0[(code>>8)-4];
+ else if(code >= 512)
+ tab = &DCTtab1[(code>>6)-8];
+ else if(code >= 256)
+ tab = &DCTtab2[(code>>4)-16];
+ else if(code >= 128)
+ tab = &DCTtab3[(code>>3)-16];
+ else if(code >= 64)
+ tab = &DCTtab4[(code>>2)-16];
+ else if(code >= 32)
+ tab = &DCTtab5[(code>>1)-16];
+ else if(code >= 16)
+ tab = &DCTtab6[code-16];
+ else
+ {
+ Fault_Flag = 1;
+ return;
+ }
+
+ Flush_Buffer(tab->len);
+
+ if(tab->run < 64)
+ {
+ i += tab->run;
+ val = tab->level;
+ sign = Get_Bits(1);
+ }
+ else if(tab->run == 64) /* end_of_block */
+ return;
+ else /* escape */
+ {
+ i += Get_Bits(6);
+ val = Get_Bits(12);
+
+ if(sign = (val >= 2048))
+ val = 4096 - val;
+ }
+
+ j = scan[alternate_scan][i];
+
+ val = (((val << 1) + 1) * quantizer_scale * qmat[j]) >> 5;
+ bp[j] = sign ? -val : val;
+ }
}
int CMPEG2Dec::Get_macroblock_type()
{
- int macroblock_type;
+ int macroblock_type;
- switch (picture_coding_type)
- {
- case I_TYPE:
- macroblock_type = Get_I_macroblock_type();
- break;
+ switch(picture_coding_type)
+ {
+ case I_TYPE:
+ macroblock_type = Get_I_macroblock_type();
+ break;
- case P_TYPE:
- macroblock_type = Get_P_macroblock_type();
- break;
+ case P_TYPE:
+ macroblock_type = Get_P_macroblock_type();
+ break;
- case B_TYPE:
- macroblock_type = Get_B_macroblock_type();
- break;
- }
+ case B_TYPE:
+ macroblock_type = Get_B_macroblock_type();
+ break;
+ }
- return macroblock_type;
+ return macroblock_type;
}
int CMPEG2Dec::Get_I_macroblock_type()
{
- if (Get_Bits(1))
- return 1;
+ if(Get_Bits(1))
+ return 1;
- if (!Get_Bits(1))
- Fault_Flag = 2;
+ if(!Get_Bits(1))
+ Fault_Flag = 2;
- return 17;
+ return 17;
}
int CMPEG2Dec::Get_P_macroblock_type()
{
- int code;
+ int code;
- if ((code = Show_Bits(6))>=8)
- {
- code >>= 3;
- Flush_Buffer(PMBtab0[code].len);
+ if((code = Show_Bits(6)) >= 8)
+ {
+ code >>= 3;
+ Flush_Buffer(PMBtab0[code].len);
- return PMBtab0[code].val;
- }
+ return PMBtab0[code].val;
+ }
- if (code==0)
- {
- Fault_Flag = 2;
- return 0;
- }
+ if(code == 0)
+ {
+ Fault_Flag = 2;
+ return 0;
+ }
- Flush_Buffer(PMBtab1[code].len);
+ Flush_Buffer(PMBtab1[code].len);
- return PMBtab1[code].val;
+ return PMBtab1[code].val;
}
int CMPEG2Dec::Get_B_macroblock_type()
{
- int code;
+ int code;
- if ((code = Show_Bits(6))>=8)
- {
- code >>= 2;
- Flush_Buffer(BMBtab0[code].len);
+ if((code = Show_Bits(6)) >= 8)
+ {
+ code >>= 2;
+ Flush_Buffer(BMBtab0[code].len);
- return BMBtab0[code].val;
- }
+ return BMBtab0[code].val;
+ }
- if (code==0)
- {
- Fault_Flag = 2;
- return 0;
- }
+ if(code == 0)
+ {
+ Fault_Flag = 2;
+ return 0;
+ }
- Flush_Buffer(BMBtab1[code].len);
+ Flush_Buffer(BMBtab1[code].len);
- return BMBtab1[code].val;
+ return BMBtab1[code].val;
}
int CMPEG2Dec::Get_coded_block_pattern()
{
- int code;
+ int code;
- if ((code = Show_Bits(9))>=128)
- {
- code >>= 4;
- Flush_Buffer(CBPtab0[code].len);
+ if((code = Show_Bits(9)) >= 128)
+ {
+ code >>= 4;
+ Flush_Buffer(CBPtab0[code].len);
- return CBPtab0[code].val;
- }
+ return CBPtab0[code].val;
+ }
- if (code>=8)
- {
- code >>= 1;
- Flush_Buffer(CBPtab1[code].len);
+ if(code >= 8)
+ {
+ code >>= 1;
+ Flush_Buffer(CBPtab1[code].len);
- return CBPtab1[code].val;
- }
+ return CBPtab1[code].val;
+ }
- if (code<1)
- {
- Fault_Flag = 3;
- return 0;
- }
+ if(code < 1)
+ {
+ Fault_Flag = 3;
+ return 0;
+ }
- Flush_Buffer(CBPtab2[code].len);
+ Flush_Buffer(CBPtab2[code].len);
- return CBPtab2[code].val;
+ return CBPtab2[code].val;
}
int CMPEG2Dec::Get_macroblock_address_increment()
{
- int code, val;
-
- val = 0;
-
- while ((code = Show_Bits(11))<24)
- {
- if (code!=15) /* if not macroblock_stuffing */
- {
- if (code==8) /* if macroblock_escape */
- val+= 33;
- else
- {
- Fault_Flag = 4;
- return 1;
- }
- }
- Flush_Buffer(11);
- }
-
- /* macroblock_address_increment == 1 */
- /* ('1' is in the MSB position of the lookahead) */
- if (code>=1024)
- {
- Flush_Buffer(1);
- return val + 1;
- }
-
- /* codes 00010 ... 011xx */
- if (code>=128)
- {
- /* remove leading zeros */
- code >>= 6;
- Flush_Buffer(MBAtab1[code].len);
-
- return val + MBAtab1[code].val;
- }
-
- /* codes 00000011000 ... 0000111xxxx */
- code-= 24; /* remove common base */
- Flush_Buffer(MBAtab2[code].len);
-
- return val + MBAtab2[code].val;
+ int code, val;
+
+ val = 0;
+
+ while((code = Show_Bits(11)) < 24)
+ {
+ if(code != 15) /* if not macroblock_stuffing */
+ {
+ if(code == 8) /* if macroblock_escape */
+ val += 33;
+ else
+ {
+ Fault_Flag = 4;
+ return 1;
+ }
+ }
+ Flush_Buffer(11);
+ }
+
+ /* macroblock_address_increment == 1 */
+ /* ('1' is in the MSB position of the lookahead) */
+ if(code >= 1024)
+ {
+ Flush_Buffer(1);
+ return val + 1;
+ }
+
+ /* codes 00010 ... 011xx */
+ if(code >= 128)
+ {
+ /* remove leading zeros */
+ code >>= 6;
+ Flush_Buffer(MBAtab1[code].len);
+
+ return val + MBAtab1[code].val;
+ }
+
+ /* codes 00000011000 ... 0000111xxxx */
+ code -= 24; /* remove common base */
+ Flush_Buffer(MBAtab2[code].len);
+
+ return val + MBAtab2[code].val;
}
/*
parse VLC and perform dct_diff arithmetic.
- MPEG-2: ISO/IEC 13818-2 section 7.2.1
+ MPEG-2: ISO/IEC 13818-2 section 7.2.1
Note: the arithmetic here is presented more elegantly than
the spec, yet the results, dct_diff, are the same.
*/
int CMPEG2Dec::Get_Luma_DC_dct_diff()
{
- int code, size, dct_diff;
-
- /* decode length */
- code = Show_Bits(5);
-
- if (code<31)
- {
- size = DClumtab0[code].val;
- Flush_Buffer(DClumtab0[code].len);
- }
- else
- {
- code = Show_Bits(9) - 0x1f0;
- size = DClumtab1[code].val;
- Flush_Buffer(DClumtab1[code].len);
- }
-
- if (size==0)
- dct_diff = 0;
- else
- {
- dct_diff = Get_Bits(size);
-
- if ((dct_diff & (1<<(size-1)))==0)
- dct_diff-= (1<<size) - 1;
- }
-
- return dct_diff;
+ int code, size, dct_diff;
+
+ /* decode length */
+ code = Show_Bits(5);
+
+ if(code < 31)
+ {
+ size = DClumtab0[code].val;
+ Flush_Buffer(DClumtab0[code].len);
+ }
+ else
+ {
+ code = Show_Bits(9) - 0x1f0;
+ size = DClumtab1[code].val;
+ Flush_Buffer(DClumtab1[code].len);
+ }
+
+ if(size == 0)
+ dct_diff = 0;
+ else
+ {
+ dct_diff = Get_Bits(size);
+
+ if((dct_diff & (1 << (size - 1))) == 0)
+ dct_diff -= (1 << size) - 1;
+ }
+
+ return dct_diff;
}
int CMPEG2Dec::Get_Chroma_DC_dct_diff()
{
- int code, size, dct_diff;
-
- /* decode length */
- code = Show_Bits(5);
-
- if (code<31)
- {
- size = DCchromtab0[code].val;
- Flush_Buffer(DCchromtab0[code].len);
- }
- else
- {
- code = Show_Bits(10) - 0x3e0;
- size = DCchromtab1[code].val;
- Flush_Buffer(DCchromtab1[code].len);
- }
-
- if (size==0)
- dct_diff = 0;
- else
- {
- dct_diff = Get_Bits(size);
-
- if ((dct_diff & (1<<(size-1)))==0)
- dct_diff-= (1<<size) - 1;
- }
-
- return dct_diff;
+ int code, size, dct_diff;
+
+ /* decode length */
+ code = Show_Bits(5);
+
+ if(code < 31)
+ {
+ size = DCchromtab0[code].val;
+ Flush_Buffer(DCchromtab0[code].len);
+ }
+ else
+ {
+ code = Show_Bits(10) - 0x3e0;
+ size = DCchromtab1[code].val;
+ Flush_Buffer(DCchromtab1[code].len);
+ }
+
+ if(size == 0)
+ dct_diff = 0;
+ else
+ {
+ dct_diff = Get_Bits(size);
+
+ if((dct_diff & (1 << (size - 1))) == 0)
+ dct_diff -= (1 << size) - 1;
+ }
+
+ return dct_diff;
}
/*
@@ -2147,691 +2153,697 @@ static int stw;
*/
void CMPEG2Dec::form_predictions(int bx, int by, int macroblock_type, int motion_type,
- int PMV[2][2][2], int motion_vertical_field_select[2][2],
- int dmvector[2])
+ int PMV[2][2][2], int motion_vertical_field_select[2][2],
+ int dmvector[2])
{
- int currentfield;
- unsigned char **predframe;
- int DMV[2][2];
- int stw;
-
- stw = 0;
-
- if ((macroblock_type & MACROBLOCK_MOTION_FORWARD) || (picture_coding_type==P_TYPE))
- {
- if (picture_structure==FRAME_PICTURE)
- {
- if ((motion_type==MC_FRAME) || !(macroblock_type & MACROBLOCK_MOTION_FORWARD))
- {
- /* frame-based prediction (broken into top and bottom halves
- for spatial scalability prediction purposes) */
- form_prediction(forward_reference_frame, 0, current_frame, 0, Coded_Picture_Width,
- Coded_Picture_Width<<1, 16, 8, bx, by, PMV[0][0][0], PMV[0][0][1], stw);
-
- form_prediction(forward_reference_frame, 1, current_frame, 1, Coded_Picture_Width,
- Coded_Picture_Width<<1, 16, 8, bx, by, PMV[0][0][0], PMV[0][0][1], stw);
- }
- else if (motion_type==MC_FIELD) /* field-based prediction */
- {
- /* top field prediction */
- form_prediction(forward_reference_frame, motion_vertical_field_select[0][0],
- current_frame, 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8,
- bx, by>>1, PMV[0][0][0], PMV[0][0][1]>>1, stw);
-
- /* bottom field prediction */
- form_prediction(forward_reference_frame, motion_vertical_field_select[1][0],
- current_frame, 1, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8,
- bx, by>>1, PMV[1][0][0], PMV[1][0][1]>>1, stw);
- }
- else if (motion_type==MC_DMV) /* dual prime prediction */
- {
- /* calculate derived motion vectors */
- Dual_Prime_Arithmetic(DMV, dmvector, PMV[0][0][0], PMV[0][0][1]>>1);
-
- /* predict top field from top field */
- form_prediction(forward_reference_frame, 0, current_frame, 0,
- Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by>>1,
- PMV[0][0][0], PMV[0][0][1]>>1, 0);
-
- /* predict and add to top field from bottom field */
- form_prediction(forward_reference_frame, 1, current_frame, 0,
- Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by>>1,
- DMV[0][0], DMV[0][1], 1);
-
- /* predict bottom field from bottom field */
- form_prediction(forward_reference_frame, 1, current_frame, 1,
- Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by>>1,
- PMV[0][0][0], PMV[0][0][1]>>1, 0);
-
- /* predict and add to bottom field from top field */
- form_prediction(forward_reference_frame, 0, current_frame, 1,
- Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by>>1,
- DMV[1][0], DMV[1][1], 1);
- }
- else
- Fault_Flag = 5;
- }
- else
- {
- /* field picture */
- currentfield = (picture_structure==BOTTOM_FIELD);
-
- /* determine which frame to use for prediction */
- if (picture_coding_type==P_TYPE && Second_Field && currentfield!=motion_vertical_field_select[0][0])
- predframe = backward_reference_frame;
- else
- predframe = forward_reference_frame;
-
- if ((motion_type==MC_FIELD) || !(macroblock_type & MACROBLOCK_MOTION_FORWARD))
- {
- form_prediction(predframe, motion_vertical_field_select[0][0], current_frame, 0,
- Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 16, bx, by,
- PMV[0][0][0], PMV[0][0][1], stw);
- }
- else if (motion_type==MC_16X8)
- {
- form_prediction(predframe, motion_vertical_field_select[0][0], current_frame, 0,
- Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by,
- PMV[0][0][0], PMV[0][0][1], stw);
-
- if (picture_coding_type==P_TYPE && Second_Field && currentfield!=motion_vertical_field_select[1][0])
- predframe = backward_reference_frame;
- else
- predframe = forward_reference_frame;
-
- form_prediction(predframe, motion_vertical_field_select[1][0], current_frame,
- 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by+8,
- PMV[1][0][0], PMV[1][0][1], stw);
- }
- else if (motion_type==MC_DMV)
- {
- if (Second_Field)
- predframe = backward_reference_frame;
- else
- predframe = forward_reference_frame;
-
- /* calculate derived motion vectors */
- Dual_Prime_Arithmetic(DMV, dmvector, PMV[0][0][0], PMV[0][0][1]);
-
- /* predict from field of same parity */
- form_prediction(forward_reference_frame, currentfield, current_frame, 0,
- Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 16, bx, by,
- PMV[0][0][0], PMV[0][0][1], 0);
-
- /* predict from field of opposite parity */
- form_prediction(predframe, !currentfield, current_frame, 0,
- Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 16, bx, by,
- DMV[0][0], DMV[0][1], 1);
- }
- else
- Fault_Flag = 5;
- }
-
- stw = 1;
- }
-
- if (macroblock_type & MACROBLOCK_MOTION_BACKWARD)
- {
- if (picture_structure==FRAME_PICTURE)
- {
- if (motion_type==MC_FRAME)
- {
- /* frame-based prediction */
- form_prediction(backward_reference_frame, 0, current_frame, 0,
- Coded_Picture_Width, Coded_Picture_Width<<1, 16, 8, bx, by,
- PMV[0][1][0], PMV[0][1][1], stw);
-
- form_prediction(backward_reference_frame, 1, current_frame, 1,
- Coded_Picture_Width, Coded_Picture_Width<<1, 16, 8, bx, by,
- PMV[0][1][0], PMV[0][1][1], stw);
- }
- else /* field-based prediction */
- {
- /* top field prediction */
- form_prediction(backward_reference_frame, motion_vertical_field_select[0][1],
- current_frame, 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8,
- bx, by>>1, PMV[0][1][0], PMV[0][1][1]>>1, stw);
-
- /* bottom field prediction */
- form_prediction(backward_reference_frame, motion_vertical_field_select[1][1],
- current_frame, 1, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8,
- bx, by>>1, PMV[1][1][0], PMV[1][1][1]>>1, stw);
- }
- }
- else
- {
- /* field picture */
- if (motion_type==MC_FIELD)
- {
- /* field-based prediction */
- form_prediction(backward_reference_frame, motion_vertical_field_select[0][1],
- current_frame, 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 16,
- bx, by, PMV[0][1][0], PMV[0][1][1], stw);
- }
- else if (motion_type==MC_16X8)
- {
- form_prediction(backward_reference_frame, motion_vertical_field_select[0][1],
- current_frame, 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8,
- bx, by, PMV[0][1][0], PMV[0][1][1], stw);
-
- form_prediction(backward_reference_frame, motion_vertical_field_select[1][1],
- current_frame, 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8,
- bx, by+8, PMV[1][1][0], PMV[1][1][1], stw);
- }
- else
- Fault_Flag = 5;
- }
- }
+ int currentfield;
+ unsigned char **predframe;
+ int DMV[2][2];
+ int stw;
+
+ stw = 0;
+
+ if((macroblock_type & MACROBLOCK_MOTION_FORWARD) || (picture_coding_type == P_TYPE))
+ {
+ if(picture_structure == FRAME_PICTURE)
+ {
+ if((motion_type == MC_FRAME) || !(macroblock_type & MACROBLOCK_MOTION_FORWARD))
+ {
+ /* frame-based prediction (broken into top and bottom halves
+ for spatial scalability prediction purposes) */
+ form_prediction(forward_reference_frame, 0, current_frame, 0, Coded_Picture_Width,
+ Coded_Picture_Width << 1, 16, 8, bx, by, PMV[0][0][0], PMV[0][0][1], stw);
+
+ form_prediction(forward_reference_frame, 1, current_frame, 1, Coded_Picture_Width,
+ Coded_Picture_Width << 1, 16, 8, bx, by, PMV[0][0][0], PMV[0][0][1], stw);
+ }
+ else if(motion_type == MC_FIELD) /* field-based prediction */
+ {
+ /* top field prediction */
+ form_prediction(forward_reference_frame, motion_vertical_field_select[0][0],
+ current_frame, 0, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8,
+ bx, by >> 1, PMV[0][0][0], PMV[0][0][1] >> 1, stw);
+
+ /* bottom field prediction */
+ form_prediction(forward_reference_frame, motion_vertical_field_select[1][0],
+ current_frame, 1, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8,
+ bx, by >> 1, PMV[1][0][0], PMV[1][0][1] >> 1, stw);
+ }
+ else if(motion_type == MC_DMV) /* dual prime prediction */
+ {
+ /* calculate derived motion vectors */
+ Dual_Prime_Arithmetic(DMV, dmvector, PMV[0][0][0], PMV[0][0][1] >> 1);
+
+ /* predict top field from top field */
+ form_prediction(forward_reference_frame, 0, current_frame, 0,
+ Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, bx, by>>1,
+ PMV[0][0][0], PMV[0][0][1] >> 1, 0);
+
+ /* predict and add to top field from bottom field */
+ form_prediction(forward_reference_frame, 1, current_frame, 0,
+ Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, bx, by>>1,
+ DMV[0][0], DMV[0][1], 1);
+
+ /* predict bottom field from bottom field */
+ form_prediction(forward_reference_frame, 1, current_frame, 1,
+ Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, bx, by>>1,
+ PMV[0][0][0], PMV[0][0][1] >> 1, 0);
+
+ /* predict and add to bottom field from top field */
+ form_prediction(forward_reference_frame, 0, current_frame, 1,
+ Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, bx, by>>1,
+ DMV[1][0], DMV[1][1], 1);
+ }
+ else
+ Fault_Flag = 5;
+ }
+ else
+ {
+ /* field picture */
+ currentfield = (picture_structure == BOTTOM_FIELD);
+
+ /* determine which frame to use for prediction */
+ if(picture_coding_type == P_TYPE && Second_Field && currentfield != motion_vertical_field_select[0][0])
+ predframe = backward_reference_frame;
+ else
+ predframe = forward_reference_frame;
+
+ if((motion_type == MC_FIELD) || !(macroblock_type & MACROBLOCK_MOTION_FORWARD))
+ {
+ form_prediction(predframe, motion_vertical_field_select[0][0], current_frame, 0,
+ Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 16, bx, by,
+ PMV[0][0][0], PMV[0][0][1], stw);
+ }
+ else if(motion_type == MC_16X8)
+ {
+ form_prediction(predframe, motion_vertical_field_select[0][0], current_frame, 0,
+ Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, bx, by,
+ PMV[0][0][0], PMV[0][0][1], stw);
+
+ if(picture_coding_type == P_TYPE && Second_Field && currentfield != motion_vertical_field_select[1][0])
+ predframe = backward_reference_frame;
+ else
+ predframe = forward_reference_frame;
+
+ form_prediction(predframe, motion_vertical_field_select[1][0], current_frame,
+ 0, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, bx, by + 8,
+ PMV[1][0][0], PMV[1][0][1], stw);
+ }
+ else if(motion_type == MC_DMV)
+ {
+ if(Second_Field)
+ predframe = backward_reference_frame;
+ else
+ predframe = forward_reference_frame;
+
+ /* calculate derived motion vectors */
+ Dual_Prime_Arithmetic(DMV, dmvector, PMV[0][0][0], PMV[0][0][1]);
+
+ /* predict from field of same parity */
+ form_prediction(forward_reference_frame, currentfield, current_frame, 0,
+ Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 16, bx, by,
+ PMV[0][0][0], PMV[0][0][1], 0);
+
+ /* predict from field of opposite parity */
+ form_prediction(predframe, !currentfield, current_frame, 0,
+ Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 16, bx, by,
+ DMV[0][0], DMV[0][1], 1);
+ }
+ else
+ Fault_Flag = 5;
+ }
+
+ stw = 1;
+ }
+
+ if(macroblock_type & MACROBLOCK_MOTION_BACKWARD)
+ {
+ if(picture_structure == FRAME_PICTURE)
+ {
+ if(motion_type == MC_FRAME)
+ {
+ /* frame-based prediction */
+ form_prediction(backward_reference_frame, 0, current_frame, 0,
+ Coded_Picture_Width, Coded_Picture_Width << 1, 16, 8, bx, by,
+ PMV[0][1][0], PMV[0][1][1], stw);
+
+ form_prediction(backward_reference_frame, 1, current_frame, 1,
+ Coded_Picture_Width, Coded_Picture_Width << 1, 16, 8, bx, by,
+ PMV[0][1][0], PMV[0][1][1], stw);
+ }
+ else /* field-based prediction */
+ {
+ /* top field prediction */
+ form_prediction(backward_reference_frame, motion_vertical_field_select[0][1],
+ current_frame, 0, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8,
+ bx, by >> 1, PMV[0][1][0], PMV[0][1][1] >> 1, stw);
+
+ /* bottom field prediction */
+ form_prediction(backward_reference_frame, motion_vertical_field_select[1][1],
+ current_frame, 1, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8,
+ bx, by >> 1, PMV[1][1][0], PMV[1][1][1] >> 1, stw);
+ }
+ }
+ else
+ {
+ /* field picture */
+ if(motion_type == MC_FIELD)
+ {
+ /* field-based prediction */
+ form_prediction(backward_reference_frame, motion_vertical_field_select[0][1],
+ current_frame, 0, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 16,
+ bx, by, PMV[0][1][0], PMV[0][1][1], stw);
+ }
+ else if(motion_type == MC_16X8)
+ {
+ form_prediction(backward_reference_frame, motion_vertical_field_select[0][1],
+ current_frame, 0, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8,
+ bx, by, PMV[0][1][0], PMV[0][1][1], stw);
+
+ form_prediction(backward_reference_frame, motion_vertical_field_select[1][1],
+ current_frame, 0, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8,
+ bx, by + 8, PMV[1][1][0], PMV[1][1][1], stw);
+ }
+ else
+ Fault_Flag = 5;
+ }
+ }
}
void CMPEG2Dec::form_prediction(unsigned char *src[], int sfield, unsigned char *dst[],
- int dfield, int lx, int lx2, int w, int h, int x, int y,
- int dx, int dy, int average_flag)
+ int dfield, int lx, int lx2, int w, int h, int x, int y,
+ int dx, int dy, int average_flag)
{
- form_component_prediction(src[0]+(sfield?lx2>>1:0), dst[0]+(dfield?lx2>>1:0),
- lx, lx2, w, h, x, y, dx, dy, average_flag);
-
- if (chroma_format!=CHROMA444)
- {
- lx>>=1; lx2>>=1; w>>=1; x>>=1; dx/=2;
- }
-
- if (chroma_format==CHROMA420)
- {
- h>>=1; y>>=1; dy/=2;
- }
-
- /* Cb */
- form_component_prediction(src[1]+(sfield?lx2>>1:0), dst[1]+(dfield?lx2>>1:0),
- lx, lx2, w, h, x, y, dx, dy, average_flag);
-
- /* Cr */
- form_component_prediction(src[2]+(sfield?lx2>>1:0), dst[2]+(dfield?lx2>>1:0),
- lx, lx2, w, h, x, y, dx, dy, average_flag);
+ form_component_prediction(src[0] + (sfield ? lx2 >> 1 : 0), dst[0] + (dfield ? lx2 >> 1 : 0),
+ lx, lx2, w, h, x, y, dx, dy, average_flag);
+
+ if(chroma_format != CHROMA444)
+ {
+ lx >>= 1;
+ lx2 >>= 1;
+ w >>= 1;
+ x >>= 1;
+ dx /= 2;
+ }
+
+ if(chroma_format == CHROMA420)
+ {
+ h >>= 1;
+ y >>= 1;
+ dy /= 2;
+ }
+
+ /* Cb */
+ form_component_prediction(src[1] + (sfield ? lx2 >> 1 : 0), dst[1] + (dfield ? lx2 >> 1 : 0),
+ lx, lx2, w, h, x, y, dx, dy, average_flag);
+
+ /* Cr */
+ form_component_prediction(src[2] + (sfield ? lx2 >> 1 : 0), dst[2] + (dfield ? lx2 >> 1 : 0),
+ lx, lx2, w, h, x, y, dx, dy, average_flag);
}
/* ISO/IEC 13818-2 section 7.6.4: Forming predictions */
void CMPEG2Dec::form_component_prediction(unsigned char *src, unsigned char *dst,
- int lx, int lx2, int w, int h, int x, int y,
- int dx, int dy, int average_flag)
+ int lx, int lx2, int w, int h, int x, int y,
+ int dx, int dy, int average_flag)
{
- static const __int64 mmmask_0001 = 0x0001000100010001;
- static const __int64 mmmask_0002 = 0x0002000200020002;
- static const __int64 mmmask_0003 = 0x0003000300030003;
- static const __int64 mmmask_0006 = 0x0006000600060006;
-
- unsigned char *s = src + lx * (y + (dy>>1)) + x + (dx>>1);
- unsigned char *d = dst + lx * y + x;
- int flag = (average_flag<<2) + ((dx & 1)<<1) + (dy & 1);
-
- switch (flag)
- {
- case 0:
- // d[i] = s[i];
- __asm
- {
- mov eax, [s]
- mov ebx, [d]
- mov esi, 0x00
- mov edi, [h]
-mc0:
- movq mm1, [eax+esi]
- add esi, 0x08
- cmp esi, [w]
- movq [ebx+esi-8], mm1
- jl mc0
-
- add eax, [lx2]
- add ebx, [lx2]
- dec edi
- mov esi, 0x00
- cmp edi, 0x00
- jg mc0
- }
- break;
-
- case 1:
- // d[i] = (s[i]+s[i+lx]+1)>>1;
- __asm
- {
- pxor mm0, mm0
- movq mm7, [mmmask_0001]
- mov eax, [s]
- mov ebx, [d]
- mov ecx, eax
- add ecx, [lx]
- mov esi, 0x00
- mov edi, [h]
-mc1:
- movq mm1, [eax+esi]
- movq mm2, [ecx+esi]
-
- movq mm3, mm1
- movq mm4, mm2
-
- punpcklbw mm1, mm0
- punpckhbw mm3, mm0
- punpcklbw mm2, mm0
- punpckhbw mm4, mm0
-
- paddsw mm1, mm2
- paddsw mm3, mm4
-
- paddsw mm1, mm7
- paddsw mm3, mm7
-
- psrlw mm1, 1
- psrlw mm3, 1
-
- packuswb mm1, mm0
- packuswb mm3, mm0
-
- psllq mm3, 32
- por mm1, mm3
-
- add esi, 0x08
- cmp esi, [w]
- movq [ebx+esi-8], mm1
- jl mc1
-
- add eax, [lx2]
- add ebx, [lx2]
- add ecx, [lx2]
- dec edi
- mov esi, 0x00
- cmp edi, 0x00
- jg mc1
- }
- break;
-
- case 2:
- // d[i] = (s[i]+s[i+1]+1)>>1;
- __asm
- {
- pxor mm0, mm0
- movq mm7, [mmmask_0001]
- mov eax, [s]
- mov ebx, [d]
- mov esi, 0x00
- mov edi, [h]
-mc2:
- movq mm1, [eax+esi]
- movq mm2, [eax+esi+1]
-
- movq mm3, mm1
- movq mm4, mm2
-
- punpcklbw mm1, mm0
- punpckhbw mm3, mm0
-
- punpcklbw mm2, mm0
- punpckhbw mm4, mm0
-
- paddsw mm1, mm2
- paddsw mm3, mm4
-
- paddsw mm1, mm7
- paddsw mm3, mm7
-
- psrlw mm1, 1
- psrlw mm3, 1
-
- packuswb mm1, mm0
- packuswb mm3, mm0
-
- psllq mm3, 32
- por mm1, mm3
-
- add esi, 0x08
- cmp esi, [w]
- movq [ebx+esi-8], mm1
- jl mc2
-
- add eax, [lx2]
- add ebx, [lx2]
- dec edi
- mov esi, 0x00
- cmp edi, 0x00
- jg mc2
- }
- break;
-
- case 3:
- // d[i] = (s[i]+s[i+1]+s[i+lx]+s[i+lx+1]+2)>>2;
- __asm
- {
- pxor mm0, mm0
- movq mm7, [mmmask_0002]
- mov eax, [s]
- mov ebx, [d]
- mov ecx, eax
- add ecx, [lx]
- mov esi, 0x00
- mov edi, [h]
-mc3:
- movq mm1, [eax+esi]
- movq mm2, [eax+esi+1]
- movq mm3, mm1
- movq mm4, mm2
-
- punpcklbw mm1, mm0
- punpckhbw mm3, mm0
-
- punpcklbw mm2, mm0
- punpckhbw mm4, mm0
-
- paddsw mm1, mm2
- paddsw mm3, mm4
-
- movq mm5, [ecx+esi]
- paddsw mm1, mm7
-
- movq mm6, [ecx+esi+1]
- paddsw mm3, mm7
-
- movq mm2, mm5
- movq mm4, mm6
-
- punpcklbw mm2, mm0
- punpckhbw mm5, mm0
-
- punpcklbw mm4, mm0
- punpckhbw mm6, mm0
-
- paddsw mm2, mm4
- paddsw mm5, mm6
-
- paddsw mm1, mm2
- paddsw mm3, mm5
-
- psrlw mm1, 2
- psrlw mm3, 2
-
- packuswb mm1, mm0
- packuswb mm3, mm0
-
- psllq mm3, 32
- por mm1, mm3
-
- add esi, 0x08
- cmp esi, [w]
- movq [ebx+esi-8], mm1
- jl mc3
-
- add eax, [lx2]
- add ebx, [lx2]
- add ecx, [lx2]
- dec edi
- mov esi, 0x00
- cmp edi, 0x00
- jg mc3
- }
- break;
-
- case 4:
- // d[i] = (s[i]+d[i]+1)>>1;
- __asm
- {
- pxor mm0, mm0
- movq mm7, [mmmask_0001]
- mov eax, [s]
- mov ebx, [d]
- mov esi, 0x00
- mov edi, [h]
-mc4:
- movq mm1, [eax+esi]
- movq mm2, [ebx+esi]
- movq mm3, mm1
- movq mm4, mm2
-
- punpcklbw mm1, mm0
- punpckhbw mm3, mm0
-
- punpcklbw mm2, mm0
- punpckhbw mm4, mm0
-
- paddsw mm1, mm2
- paddsw mm3, mm4
-
- paddsw mm1, mm7
- paddsw mm3, mm7
-
- psrlw mm1, 1
- psrlw mm3, 1
-
- packuswb mm1, mm0
- packuswb mm3, mm0
-
- psllq mm3, 32
- por mm1, mm3
-
- add esi, 0x08
- cmp esi, [w]
- movq [ebx+esi-8], mm1
- jl mc4
-
- add eax, [lx2]
- add ebx, [lx2]
- dec edi
- mov esi, 0x00
- cmp edi, 0x00
- jg mc4
- }
- break;
-
- case 5:
- // d[i] = ((d[i]<<1) + s[i]+s[i+lx] + 3)>>2;
- __asm
- {
- pxor mm0, mm0
- movq mm7, [mmmask_0003]
- mov eax, [s]
- mov ebx, [d]
- mov ecx, eax
- add ecx, [lx]
- mov esi, 0x00
- mov edi, [h]
-mc5:
- movq mm1, [eax+esi]
- movq mm2, [ecx+esi]
- movq mm3, mm1
- movq mm4, mm2
-
- punpcklbw mm1, mm0
- punpckhbw mm3, mm0
-
- punpcklbw mm2, mm0
- punpckhbw mm4, mm0
-
- paddsw mm1, mm2
- paddsw mm3, mm4
-
- movq mm5, [ebx+esi]
-
- paddsw mm1, mm7
- paddsw mm3, mm7
-
- movq mm6, mm5
- punpcklbw mm5, mm0
- punpckhbw mm6, mm0
-
- psllw mm5, 1
- psllw mm6, 1
-
- paddsw mm1, mm5
- paddsw mm3, mm6
-
- psrlw mm1, 2
- psrlw mm3, 2
-
- packuswb mm1, mm0
- packuswb mm3, mm0
-
- psllq mm3, 32
- por mm1, mm3
-
- add esi, 0x08
- cmp esi, [w]
- movq [ebx+esi-8], mm1
- jl mc5
-
- add eax, [lx2]
- add ebx, [lx2]
- add ecx, [lx2]
- dec edi
- mov esi, 0x00
- cmp edi, 0x00
- jg mc5
- }
- break;
-
- case 6:
- // d[i] = ((d[i]<<1) + s[i]+s[i+1] + 3) >> 2;
- __asm
- {
- pxor mm0, mm0
- movq mm7, [mmmask_0003]
- mov eax, [s]
- mov ebx, [d]
- mov esi, 0x00
- mov edi, [h]
-mc6:
- movq mm1, [eax+esi]
- movq mm2, [eax+esi+1]
- movq mm3, mm1
- movq mm4, mm2
-
- punpcklbw mm1, mm0
- punpckhbw mm3, mm0
-
- punpcklbw mm2, mm0
- punpckhbw mm4, mm0
-
- paddsw mm1, mm2
- paddsw mm3, mm4
-
- movq mm5, [ebx+esi]
-
- paddsw mm1, mm7
- paddsw mm3, mm7
-
- movq mm6, mm5
- punpcklbw mm5, mm0
- punpckhbw mm6, mm0
-
- psllw mm5, 1
- psllw mm6, 1
-
- paddsw mm1, mm5
- paddsw mm3, mm6
-
- psrlw mm1, 2
- psrlw mm3, 2
-
- packuswb mm1, mm0
- packuswb mm3, mm0
-
- psllq mm3, 32
- por mm1, mm3
-
- add esi, 0x08
- cmp esi, [w]
- movq [ebx+esi-8], mm1
- jl mc6
-
- add eax, [lx2]
- add ebx, [lx2]
- dec edi
- mov esi, 0x00
- cmp edi, 0x00
- jg mc6
- }
- break;
-
- case 7:
- // d[i] = ((d[i]<<2) + s[i]+s[i+1]+s[i+lx]+s[i+lx+1] + 6)>>3;
- __asm
- {
- pxor mm0, mm0
- movq mm7, [mmmask_0006]
- mov eax, [s]
- mov ebx, [d]
- mov ecx, eax
- add ecx, [lx]
- mov esi, 0x00
- mov edi, [h]
-mc7:
- movq mm1, [eax+esi]
- movq mm2, [eax+esi+1]
- movq mm3, mm1
- movq mm4, mm2
-
- punpcklbw mm1, mm0
- punpckhbw mm3, mm0
-
- punpcklbw mm2, mm0
- punpckhbw mm4, mm0
-
- paddsw mm1, mm2
- paddsw mm3, mm4
-
- movq mm5, [ecx+esi]
- paddsw mm1, mm7
-
- movq mm6, [ecx+esi+1]
- paddsw mm3, mm7
-
- movq mm2, mm5
- movq mm4, mm6
-
- punpcklbw mm2, mm0
- punpckhbw mm5, mm0
-
- punpcklbw mm4, mm0
- punpckhbw mm6, mm0
-
- paddsw mm2, mm4
- paddsw mm5, mm6
-
- paddsw mm1, mm2
- paddsw mm3, mm5
-
- movq mm6, [ebx+esi]
-
- movq mm4, mm6
- punpcklbw mm4, mm0
- punpckhbw mm6, mm0
-
- psllw mm4, 2
- psllw mm6, 2
-
- paddsw mm1, mm4
- paddsw mm3, mm6
-
- psrlw mm1, 3
- psrlw mm3, 3
-
- packuswb mm1, mm0
- packuswb mm3, mm0
-
- psllq mm3, 32
- por mm1, mm3
-
- add esi, 0x08
- cmp esi, [w]
- movq [ebx+esi-8], mm1
- jl mc7
-
- add eax, [lx2]
- add ebx, [lx2]
- add ecx, [lx2]
- dec edi
- mov esi, 0x00
- cmp edi, 0x00
- jg mc7
- }
- break;
- }
+ static const __int64 mmmask_0001 = 0x0001000100010001;
+ static const __int64 mmmask_0002 = 0x0002000200020002;
+ static const __int64 mmmask_0003 = 0x0003000300030003;
+ static const __int64 mmmask_0006 = 0x0006000600060006;
+
+ unsigned char *s = src + lx * (y + (dy >> 1)) + x + (dx >> 1);
+ unsigned char *d = dst + lx * y + x;
+ int flag = (average_flag << 2) + ((dx & 1) << 1) + (dy & 1);
+
+ switch(flag)
+ {
+ case 0:
+ // d[i] = s[i];
+ __asm
+ {
+ mov eax, [s]
+ mov ebx, [d]
+ mov esi, 0x00
+ mov edi, [h]
+ mc0:
+ movq mm1, [eax+esi]
+ add esi, 0x08
+ cmp esi, [w]
+ movq [ebx+esi-8], mm1
+ jl mc0
+
+ add eax, [lx2]
+ add ebx, [lx2]
+ dec edi
+ mov esi, 0x00
+ cmp edi, 0x00
+ jg mc0
+ }
+ break;
+
+ case 1:
+ // d[i] = (s[i]+s[i+lx]+1)>>1;
+ __asm
+ {
+ pxor mm0, mm0
+ movq mm7, [mmmask_0001]
+ mov eax, [s]
+ mov ebx, [d]
+ mov ecx, eax
+ add ecx, [lx]
+ mov esi, 0x00
+ mov edi, [h]
+ mc1:
+ movq mm1, [eax+esi]
+ movq mm2, [ecx+esi]
+
+ movq mm3, mm1
+ movq mm4, mm2
+
+ punpcklbw mm1, mm0
+ punpckhbw mm3, mm0
+ punpcklbw mm2, mm0
+ punpckhbw mm4, mm0
+
+ paddsw mm1, mm2
+ paddsw mm3, mm4
+
+ paddsw mm1, mm7
+ paddsw mm3, mm7
+
+ psrlw mm1, 1
+ psrlw mm3, 1
+
+ packuswb mm1, mm0
+ packuswb mm3, mm0
+
+ psllq mm3, 32
+ por mm1, mm3
+
+ add esi, 0x08
+ cmp esi, [w]
+ movq [ebx+esi-8], mm1
+ jl mc1
+
+ add eax, [lx2]
+ add ebx, [lx2]
+ add ecx, [lx2]
+ dec edi
+ mov esi, 0x00
+ cmp edi, 0x00
+ jg mc1
+ }
+ break;
+
+ case 2:
+ // d[i] = (s[i]+s[i+1]+1)>>1;
+ __asm
+ {
+ pxor mm0, mm0
+ movq mm7, [mmmask_0001]
+ mov eax, [s]
+ mov ebx, [d]
+ mov esi, 0x00
+ mov edi, [h]
+ mc2:
+ movq mm1, [eax+esi]
+ movq mm2, [eax+esi+1]
+
+ movq mm3, mm1
+ movq mm4, mm2
+
+ punpcklbw mm1, mm0
+ punpckhbw mm3, mm0
+
+ punpcklbw mm2, mm0
+ punpckhbw mm4, mm0
+
+ paddsw mm1, mm2
+ paddsw mm3, mm4
+
+ paddsw mm1, mm7
+ paddsw mm3, mm7
+
+ psrlw mm1, 1
+ psrlw mm3, 1
+
+ packuswb mm1, mm0
+ packuswb mm3, mm0
+
+ psllq mm3, 32
+ por mm1, mm3
+
+ add esi, 0x08
+ cmp esi, [w]
+ movq [ebx+esi-8], mm1
+ jl mc2
+
+ add eax, [lx2]
+ add ebx, [lx2]
+ dec edi
+ mov esi, 0x00
+ cmp edi, 0x00
+ jg mc2
+ }
+ break;
+
+ case 3:
+ // d[i] = (s[i]+s[i+1]+s[i+lx]+s[i+lx+1]+2)>>2;
+ __asm
+ {
+ pxor mm0, mm0
+ movq mm7, [mmmask_0002]
+ mov eax, [s]
+ mov ebx, [d]
+ mov ecx, eax
+ add ecx, [lx]
+ mov esi, 0x00
+ mov edi, [h]
+ mc3:
+ movq mm1, [eax+esi]
+ movq mm2, [eax+esi+1]
+ movq mm3, mm1
+ movq mm4, mm2
+
+ punpcklbw mm1, mm0
+ punpckhbw mm3, mm0
+
+ punpcklbw mm2, mm0
+ punpckhbw mm4, mm0
+
+ paddsw mm1, mm2
+ paddsw mm3, mm4
+
+ movq mm5, [ecx+esi]
+ paddsw mm1, mm7
+
+ movq mm6, [ecx+esi+1]
+ paddsw mm3, mm7
+
+ movq mm2, mm5
+ movq mm4, mm6
+
+ punpcklbw mm2, mm0
+ punpckhbw mm5, mm0
+
+ punpcklbw mm4, mm0
+ punpckhbw mm6, mm0
+
+ paddsw mm2, mm4
+ paddsw mm5, mm6
+
+ paddsw mm1, mm2
+ paddsw mm3, mm5
+
+ psrlw mm1, 2
+ psrlw mm3, 2
+
+ packuswb mm1, mm0
+ packuswb mm3, mm0
+
+ psllq mm3, 32
+ por mm1, mm3
+
+ add esi, 0x08
+ cmp esi, [w]
+ movq [ebx+esi-8], mm1
+ jl mc3
+
+ add eax, [lx2]
+ add ebx, [lx2]
+ add ecx, [lx2]
+ dec edi
+ mov esi, 0x00
+ cmp edi, 0x00
+ jg mc3
+ }
+ break;
+
+ case 4:
+ // d[i] = (s[i]+d[i]+1)>>1;
+ __asm
+ {
+ pxor mm0, mm0
+ movq mm7, [mmmask_0001]
+ mov eax, [s]
+ mov ebx, [d]
+ mov esi, 0x00
+ mov edi, [h]
+ mc4:
+ movq mm1, [eax+esi]
+ movq mm2, [ebx+esi]
+ movq mm3, mm1
+ movq mm4, mm2
+
+ punpcklbw mm1, mm0
+ punpckhbw mm3, mm0
+
+ punpcklbw mm2, mm0
+ punpckhbw mm4, mm0
+
+ paddsw mm1, mm2
+ paddsw mm3, mm4
+
+ paddsw mm1, mm7
+ paddsw mm3, mm7
+
+ psrlw mm1, 1
+ psrlw mm3, 1
+
+ packuswb mm1, mm0
+ packuswb mm3, mm0
+
+ psllq mm3, 32
+ por mm1, mm3
+
+ add esi, 0x08
+ cmp esi, [w]
+ movq [ebx+esi-8], mm1
+ jl mc4
+
+ add eax, [lx2]
+ add ebx, [lx2]
+ dec edi
+ mov esi, 0x00
+ cmp edi, 0x00
+ jg mc4
+ }
+ break;
+
+ case 5:
+ // d[i] = ((d[i]<<1) + s[i]+s[i+lx] + 3)>>2;
+ __asm
+ {
+ pxor mm0, mm0
+ movq mm7, [mmmask_0003]
+ mov eax, [s]
+ mov ebx, [d]
+ mov ecx, eax
+ add ecx, [lx]
+ mov esi, 0x00
+ mov edi, [h]
+ mc5:
+ movq mm1, [eax+esi]
+ movq mm2, [ecx+esi]
+ movq mm3, mm1
+ movq mm4, mm2
+
+ punpcklbw mm1, mm0
+ punpckhbw mm3, mm0
+
+ punpcklbw mm2, mm0
+ punpckhbw mm4, mm0
+
+ paddsw mm1, mm2
+ paddsw mm3, mm4
+
+ movq mm5, [ebx+esi]
+
+ paddsw mm1, mm7
+ paddsw mm3, mm7
+
+ movq mm6, mm5
+ punpcklbw mm5, mm0
+ punpckhbw mm6, mm0
+
+ psllw mm5, 1
+ psllw mm6, 1
+
+ paddsw mm1, mm5
+ paddsw mm3, mm6
+
+ psrlw mm1, 2
+ psrlw mm3, 2
+
+ packuswb mm1, mm0
+ packuswb mm3, mm0
+
+ psllq mm3, 32
+ por mm1, mm3
+
+ add esi, 0x08
+ cmp esi, [w]
+ movq [ebx+esi-8], mm1
+ jl mc5
+
+ add eax, [lx2]
+ add ebx, [lx2]
+ add ecx, [lx2]
+ dec edi
+ mov esi, 0x00
+ cmp edi, 0x00
+ jg mc5
+ }
+ break;
+
+ case 6:
+ // d[i] = ((d[i]<<1) + s[i]+s[i+1] + 3) >> 2;
+ __asm
+ {
+ pxor mm0, mm0
+ movq mm7, [mmmask_0003]
+ mov eax, [s]
+ mov ebx, [d]
+ mov esi, 0x00
+ mov edi, [h]
+ mc6:
+ movq mm1, [eax+esi]
+ movq mm2, [eax+esi+1]
+ movq mm3, mm1
+ movq mm4, mm2
+
+ punpcklbw mm1, mm0
+ punpckhbw mm3, mm0
+
+ punpcklbw mm2, mm0
+ punpckhbw mm4, mm0
+
+ paddsw mm1, mm2
+ paddsw mm3, mm4
+
+ movq mm5, [ebx+esi]
+
+ paddsw mm1, mm7
+ paddsw mm3, mm7
+
+ movq mm6, mm5
+ punpcklbw mm5, mm0
+ punpckhbw mm6, mm0
+
+ psllw mm5, 1
+ psllw mm6, 1
+
+ paddsw mm1, mm5
+ paddsw mm3, mm6
+
+ psrlw mm1, 2
+ psrlw mm3, 2
+
+ packuswb mm1, mm0
+ packuswb mm3, mm0
+
+ psllq mm3, 32
+ por mm1, mm3
+
+ add esi, 0x08
+ cmp esi, [w]
+ movq [ebx+esi-8], mm1
+ jl mc6
+
+ add eax, [lx2]
+ add ebx, [lx2]
+ dec edi
+ mov esi, 0x00
+ cmp edi, 0x00
+ jg mc6
+ }
+ break;
+
+ case 7:
+ // d[i] = ((d[i]<<2) + s[i]+s[i+1]+s[i+lx]+s[i+lx+1] + 6)>>3;
+ __asm
+ {
+ pxor mm0, mm0
+ movq mm7, [mmmask_0006]
+ mov eax, [s]
+ mov ebx, [d]
+ mov ecx, eax
+ add ecx, [lx]
+ mov esi, 0x00
+ mov edi, [h]
+ mc7:
+ movq mm1, [eax+esi]
+ movq mm2, [eax+esi+1]
+ movq mm3, mm1
+ movq mm4, mm2
+
+ punpcklbw mm1, mm0
+ punpckhbw mm3, mm0
+
+ punpcklbw mm2, mm0
+ punpckhbw mm4, mm0
+
+ paddsw mm1, mm2
+ paddsw mm3, mm4
+
+ movq mm5, [ecx+esi]
+ paddsw mm1, mm7
+
+ movq mm6, [ecx+esi+1]
+ paddsw mm3, mm7
+
+ movq mm2, mm5
+ movq mm4, mm6
+
+ punpcklbw mm2, mm0
+ punpckhbw mm5, mm0
+
+ punpcklbw mm4, mm0
+ punpckhbw mm6, mm0
+
+ paddsw mm2, mm4
+ paddsw mm5, mm6
+
+ paddsw mm1, mm2
+ paddsw mm3, mm5
+
+ movq mm6, [ebx+esi]
+
+ movq mm4, mm6
+ punpcklbw mm4, mm0
+ punpckhbw mm6, mm0
+
+ psllw mm4, 2
+ psllw mm6, 2
+
+ paddsw mm1, mm4
+ paddsw mm3, mm6
+
+ psrlw mm1, 3
+ psrlw mm3, 3
+
+ packuswb mm1, mm0
+ packuswb mm3, mm0
+
+ psllq mm3, 32
+ por mm1, mm3
+
+ add esi, 0x08
+ cmp esi, [w]
+ movq [ebx+esi-8], mm1
+ jl mc7
+
+ add eax, [lx2]
+ add ebx, [lx2]
+ add ecx, [lx2]
+ dec edi
+ mov esi, 0x00
+ cmp edi, 0x00
+ jg mc7
+ }
+ break;
+ }
}
//
@@ -2839,175 +2851,175 @@ mc7:
//
/* ISO/IEC 13818-2 sections 6.2.5.2, 6.3.17.2, and 7.6.3: Motion vectors */
-void CMPEG2Dec::motion_vectors(int PMV[2][2][2],int dmvector[2],
- int motion_vertical_field_select[2][2], int s,
- int motion_vector_count, int mv_format, int h_r_size,
- int v_r_size, int dmv, int mvscale)
+void CMPEG2Dec::motion_vectors(int PMV[2][2][2], int dmvector[2],
+ int motion_vertical_field_select[2][2], int s,
+ int motion_vector_count, int mv_format, int h_r_size,
+ int v_r_size, int dmv, int mvscale)
{
- if (motion_vector_count==1)
- {
- if (mv_format==MV_FIELD && !dmv)
- motion_vertical_field_select[1][s] =
- motion_vertical_field_select[0][s] = Get_Bits(1);
-
- motion_vector(PMV[0][s],dmvector,h_r_size,v_r_size,dmv,mvscale,0);
-
- /* update other motion vector predictors */
- PMV[1][s][0] = PMV[0][s][0];
- PMV[1][s][1] = PMV[0][s][1];
- }
- else
- {
- motion_vertical_field_select[0][s] = Get_Bits(1);
- motion_vector(PMV[0][s],dmvector,h_r_size,v_r_size,dmv,mvscale,0);
- motion_vertical_field_select[1][s] = Get_Bits(1);
- motion_vector(PMV[1][s],dmvector,h_r_size,v_r_size,dmv,mvscale,0);
- }
+ if(motion_vector_count == 1)
+ {
+ if(mv_format == MV_FIELD && !dmv)
+ motion_vertical_field_select[1][s] =
+ motion_vertical_field_select[0][s] = Get_Bits(1);
+
+ motion_vector(PMV[0][s], dmvector, h_r_size, v_r_size, dmv, mvscale, 0);
+
+ /* update other motion vector predictors */
+ PMV[1][s][0] = PMV[0][s][0];
+ PMV[1][s][1] = PMV[0][s][1];
+ }
+ else
+ {
+ motion_vertical_field_select[0][s] = Get_Bits(1);
+ motion_vector(PMV[0][s], dmvector, h_r_size, v_r_size, dmv, mvscale, 0);
+ motion_vertical_field_select[1][s] = Get_Bits(1);
+ motion_vector(PMV[1][s], dmvector, h_r_size, v_r_size, dmv, mvscale, 0);
+ }
}
/* ISO/IEC 13818-2 section 7.6.3.6: Dual prime additional arithmetic */
-void CMPEG2Dec::Dual_Prime_Arithmetic(int DMV[][2],int *dmvector, int mvx,int mvy)
+void CMPEG2Dec::Dual_Prime_Arithmetic(int DMV[][2], int *dmvector, int mvx, int mvy)
{
- if (picture_structure==FRAME_PICTURE)
- {
- if (top_field_first)
- {
- /* vector for prediction of top field from bottom field */
- DMV[0][0] = ((mvx +(mvx>0))>>1) + dmvector[0];
- DMV[0][1] = ((mvy +(mvy>0))>>1) + dmvector[1] - 1;
-
- /* vector for prediction of bottom field from top field */
- DMV[1][0] = ((3*mvx+(mvx>0))>>1) + dmvector[0];
- DMV[1][1] = ((3*mvy+(mvy>0))>>1) + dmvector[1] + 1;
- }
- else
- {
- /* vector for prediction of top field from bottom field */
- DMV[0][0] = ((3*mvx+(mvx>0))>>1) + dmvector[0];
- DMV[0][1] = ((3*mvy+(mvy>0))>>1) + dmvector[1] - 1;
-
- /* vector for prediction of bottom field from top field */
- DMV[1][0] = ((mvx +(mvx>0))>>1) + dmvector[0];
- DMV[1][1] = ((mvy +(mvy>0))>>1) + dmvector[1] + 1;
- }
- }
- else
- {
- /* vector for prediction from field of opposite 'parity' */
- DMV[0][0] = ((mvx+(mvx>0))>>1) + dmvector[0];
- DMV[0][1] = ((mvy+(mvy>0))>>1) + dmvector[1];
-
- /* correct for vertical field shift */
- if (picture_structure==TOP_FIELD)
- DMV[0][1]--;
- else
- DMV[0][1]++;
- }
+ if(picture_structure == FRAME_PICTURE)
+ {
+ if(top_field_first)
+ {
+ /* vector for prediction of top field from bottom field */
+ DMV[0][0] = ((mvx + (mvx > 0)) >> 1) + dmvector[0];
+ DMV[0][1] = ((mvy + (mvy > 0)) >> 1) + dmvector[1] - 1;
+
+ /* vector for prediction of bottom field from top field */
+ DMV[1][0] = ((3 * mvx + (mvx > 0)) >> 1) + dmvector[0];
+ DMV[1][1] = ((3 * mvy + (mvy > 0)) >> 1) + dmvector[1] + 1;
+ }
+ else
+ {
+ /* vector for prediction of top field from bottom field */
+ DMV[0][0] = ((3 * mvx + (mvx > 0)) >> 1) + dmvector[0];
+ DMV[0][1] = ((3 * mvy + (mvy > 0)) >> 1) + dmvector[1] - 1;
+
+ /* vector for prediction of bottom field from top field */
+ DMV[1][0] = ((mvx + (mvx > 0)) >> 1) + dmvector[0];
+ DMV[1][1] = ((mvy + (mvy > 0)) >> 1) + dmvector[1] + 1;
+ }
+ }
+ else
+ {
+ /* vector for prediction from field of opposite 'parity' */
+ DMV[0][0] = ((mvx + (mvx > 0)) >> 1) + dmvector[0];
+ DMV[0][1] = ((mvy + (mvy > 0)) >> 1) + dmvector[1];
+
+ /* correct for vertical field shift */
+ if(picture_structure == TOP_FIELD)
+ DMV[0][1]--;
+ else
+ DMV[0][1]++;
+ }
}
/* get and decode motion vector and differential motion vector for one prediction */
void CMPEG2Dec::motion_vector(int *PMV, int *dmvector, int h_r_size, int v_r_size,
- int dmv, int mvscale, int full_pel_vector)
+ int dmv, int mvscale, int full_pel_vector)
{
- int motion_code, motion_residual;
+ int motion_code, motion_residual;
- /* horizontal component */
- /* ISO/IEC 13818-2 Table B-10 */
- motion_code = Get_motion_code();
+ /* horizontal component */
+ /* ISO/IEC 13818-2 Table B-10 */
+ motion_code = Get_motion_code();
- motion_residual = (h_r_size!=0 && motion_code!=0) ? Get_Bits(h_r_size) : 0;
+ motion_residual = (h_r_size != 0 && motion_code != 0) ? Get_Bits(h_r_size) : 0;
- decode_motion_vector(&PMV[0],h_r_size,motion_code,motion_residual,full_pel_vector);
+ decode_motion_vector(&PMV[0], h_r_size, motion_code, motion_residual, full_pel_vector);
- if (dmv)
- dmvector[0] = Get_dmvector();
+ if(dmv)
+ dmvector[0] = Get_dmvector();
- /* vertical component */
- motion_code = Get_motion_code();
- motion_residual = (v_r_size!=0 && motion_code!=0) ? Get_Bits(v_r_size) : 0;
+ /* vertical component */
+ motion_code = Get_motion_code();
+ motion_residual = (v_r_size != 0 && motion_code != 0) ? Get_Bits(v_r_size) : 0;
- if (mvscale)
- PMV[1] >>= 1; /* DIV 2 */
+ if(mvscale)
+ PMV[1] >>= 1; /* DIV 2 */
- decode_motion_vector(&PMV[1],v_r_size,motion_code,motion_residual,full_pel_vector);
+ decode_motion_vector(&PMV[1], v_r_size, motion_code, motion_residual, full_pel_vector);
- if (mvscale)
- PMV[1] <<= 1;
+ if(mvscale)
+ PMV[1] <<= 1;
- if (dmv)
- dmvector[1] = Get_dmvector();
+ if(dmv)
+ dmvector[1] = Get_dmvector();
}
/* calculate motion vector component */
/* ISO/IEC 13818-2 section 7.6.3.1: Decoding the motion vectors */
-/* Note: the arithmetic here is more elegant than that which is shown
+/* Note: the arithmetic here is more elegant than that which is shown
in 7.6.3.1. The end results (PMV[][][]) should, however, be the same. */
void CMPEG2Dec::decode_motion_vector(int *pred, int r_size, int motion_code,
- int motion_residual, int full_pel_vector)
+ int motion_residual, int full_pel_vector)
{
- int lim, vec;
-
- lim = 16<<r_size;
- vec = full_pel_vector ? (*pred >> 1) : (*pred);
-
- if (motion_code>0)
- {
- vec+= ((motion_code-1)<<r_size) + motion_residual + 1;
- if (vec>=lim)
- vec-= lim + lim;
- }
- else if (motion_code<0)
- {
- vec-= ((-motion_code-1)<<r_size) + motion_residual + 1;
- if (vec<-lim)
- vec+= lim + lim;
- }
-
- *pred = full_pel_vector ? (vec<<1) : vec;
+ int lim, vec;
+
+ lim = 16 << r_size;
+ vec = full_pel_vector ? (*pred >> 1) : (*pred);
+
+ if(motion_code > 0)
+ {
+ vec += ((motion_code - 1) << r_size) + motion_residual + 1;
+ if(vec >= lim)
+ vec -= lim + lim;
+ }
+ else if(motion_code < 0)
+ {
+ vec -= ((-motion_code - 1) << r_size) + motion_residual + 1;
+ if(vec < -lim)
+ vec += lim + lim;
+ }
+
+ *pred = full_pel_vector ? (vec << 1) : vec;
}
int CMPEG2Dec::Get_motion_code()
{
- int code;
+ int code;
- if (Get_Bits(1))
- return 0;
+ if(Get_Bits(1))
+ return 0;
- if ((code = Show_Bits(9))>=64)
- {
- code >>= 6;
- Flush_Buffer(MVtab0[code].len);
+ if((code = Show_Bits(9)) >= 64)
+ {
+ code >>= 6;
+ Flush_Buffer(MVtab0[code].len);
- return Get_Bits(1)?-MVtab0[code].val:MVtab0[code].val;
- }
+ return Get_Bits(1) ? -MVtab0[code].val : MVtab0[code].val;
+ }
- if (code>=24)
- {
- code >>= 3;
- Flush_Buffer(MVtab1[code].len);
+ if(code >= 24)
+ {
+ code >>= 3;
+ Flush_Buffer(MVtab1[code].len);
- return Get_Bits(1)?-MVtab1[code].val:MVtab1[code].val;
- }
+ return Get_Bits(1) ? -MVtab1[code].val : MVtab1[code].val;
+ }
- if ((code-=12)<0)
- {
- Fault_Flag = 10;
- return 0;
- }
+ if((code -= 12) < 0)
+ {
+ Fault_Flag = 10;
+ return 0;
+ }
- Flush_Buffer(MVtab2[code].len);
+ Flush_Buffer(MVtab2[code].len);
- return Get_Bits(1) ? -MVtab2[code].val : MVtab2[code].val;
+ return Get_Bits(1) ? -MVtab2[code].val : MVtab2[code].val;
}
/* get differential motion vector (for dual prime prediction) */
int CMPEG2Dec::Get_dmvector()
{
- if (Get_Bits(1))
- return Get_Bits(1) ? -1 : 1;
- else
- return 0;
+ if(Get_Bits(1))
+ return Get_Bits(1) ? -1 : 1;
+ else
+ return 0;
}
//
@@ -3026,1465 +3038,1478 @@ static const __int64 mmmask_0128 = 0x0080008000800080;
void CMPEG2Dec::assembleFrame(unsigned char *src[], int pf, unsigned char *dst, int pitch)
{
- unsigned char *y444;
-
- if (Fault_Flag)
- Fault_Flag = 0;
-
- if (Luminance_Flag)
- {
- Luminance_Filter(src[0], lum);
- y444 = lum;
- }
- else
- y444 = src[0];
-
- if (chroma_format==CHROMA420)
- {
- conv420to422(src[1], u422, pf);
- conv420to422(src[2], v422, pf);
-
- if (!dstYUY2())
- {
- conv422to444(u422, u444);
- conv422to444(v422, v444);
- }
- }
- else if (!dstYUY2())
- {
- conv422to444(src[1], u444);
- conv422to444(src[2], v444);
- }
-
- if (dstYUY2())
- conv422toYUY2(y444, u422, v422, dst, pitch);
- else
- conv444toRGB24(y444, u444, v444, dst, pitch);
+ unsigned char *y444;
+
+ if(Fault_Flag)
+ Fault_Flag = 0;
+
+ if(Luminance_Flag)
+ {
+ Luminance_Filter(src[0], lum);
+ y444 = lum;
+ }
+ else
+ y444 = src[0];
+
+ if(chroma_format == CHROMA420)
+ {
+ conv420to422(src[1], u422, pf);
+ conv420to422(src[2], v422, pf);
+
+ if(!dstYUY2())
+ {
+ conv422to444(u422, u444);
+ conv422to444(v422, v444);
+ }
+ }
+ else if(!dstYUY2())
+ {
+ conv422to444(src[1], u444);
+ conv422to444(src[2], v444);
+ }
+
+ if(dstYUY2())
+ conv422toYUY2(y444, u422, v422, dst, pitch);
+ else
+ conv444toRGB24(y444, u444, v444, dst, pitch);
}
void CMPEG2Dec::Luminance_Filter(unsigned char *src, unsigned char *dst)
{
- src += CLIP_AREA;
- dst += CLIP_AREA;
-
- __asm
- {
- mov edx, this
- mov eax, [src]
- mov ebx, [dst]
- mov esi, 0x00
- mov edi, [edx].LUM_AREA
- pxor mm0, mm0
- movq mm5, [edx].LumOffsetMask
- movq mm6, [edx].LumGainMask
- movq mm7, mmmask_0040
-
-lumconv:
- movq mm1, [eax+esi]
- movq mm2, mm1
-
- punpcklbw mm1, mm0
- punpckhbw mm2, mm0
-
- pmullw mm1, mm6
- pmullw mm2, mm6
-
- paddw mm1, mm7
- paddw mm2, mm7
-
- psrlw mm1, 7
- psrlw mm2, 7
-
- paddw mm1, mm5
- paddw mm2, mm5
-
- packuswb mm1, mm0
- packuswb mm2, mm0
-
- add esi, 0x08
- cmp esi, edi
- movq [ebx+esi-8], mm1
- movq [ebx+esi-4], mm2
- jl lumconv
- }
+ src += CLIP_AREA;
+ dst += CLIP_AREA;
+
+ __asm
+ {
+ mov edx, this
+ mov eax, [src]
+ mov ebx, [dst]
+ mov esi, 0x00
+ mov edi, [edx].LUM_AREA
+ pxor mm0, mm0
+ movq mm5, [edx].LumOffsetMask
+ movq mm6, [edx].LumGainMask
+ movq mm7, mmmask_0040
+
+ lumconv:
+ movq mm1, [eax+esi]
+ movq mm2, mm1
+
+ punpcklbw mm1, mm0
+ punpckhbw mm2, mm0
+
+ pmullw mm1, mm6
+ pmullw mm2, mm6
+
+ paddw mm1, mm7
+ paddw mm2, mm7
+
+ psrlw mm1, 7
+ psrlw mm2, 7
+
+ paddw mm1, mm5
+ paddw mm2, mm5
+
+ packuswb mm1, mm0
+ packuswb mm2, mm0
+
+ add esi, 0x08
+ cmp esi, edi
+ movq [ebx+esi-8], mm1
+ movq [ebx+esi-4], mm2
+ jl lumconv
+ }
}
void CMPEG2Dec::conv422to444(unsigned char *src, unsigned char *dst)
{
- src += HALF_CLIP_AREA;
- dst += CLIP_AREA;
+ src += HALF_CLIP_AREA;
+ dst += CLIP_AREA;
- __asm
- {
- mov edx, this
- mov eax, [src]
- mov ebx, [dst]
- mov edi, [edx].Clip_Height
+ __asm
+ {
+ mov edx, this
+ mov eax, [src]
+ mov ebx, [dst]
+ mov edi, [edx].Clip_Height
- movq mm1, [mmmask_0001]
- pxor mm0, mm0
+ movq mm1, [mmmask_0001]
+ pxor mm0, mm0
-convyuv444init:
- movq mm7, [eax]
- mov esi, 0x00
+ convyuv444init:
+ movq mm7, [eax]
+ mov esi, 0x00
-convyuv444:
- movq mm2, mm7
- movq mm7, [eax+esi+8]
- movq mm3, mm2
- movq mm4, mm7
+ convyuv444:
+ movq mm2, mm7
+ movq mm7, [eax+esi+8]
+ movq mm3, mm2
+ movq mm4, mm7
- psrlq mm3, 8
- psllq mm4, 56
- por mm3, mm4
+ psrlq mm3, 8
+ psllq mm4, 56
+ por mm3, mm4
- movq mm4, mm2
- movq mm5, mm3
+ movq mm4, mm2
+ movq mm5, mm3
- punpcklbw mm4, mm0
- punpcklbw mm5, mm0
+ punpcklbw mm4, mm0
+ punpcklbw mm5, mm0
- movq mm6, mm4
- paddusw mm4, mm1
- paddusw mm4, mm5
- psrlw mm4, 1
- psllq mm4, 8
- por mm4, mm6
+ movq mm6, mm4
+ paddusw mm4, mm1
+ paddusw mm4, mm5
+ psrlw mm4, 1
+ psllq mm4, 8
+ por mm4, mm6
- punpckhbw mm2, mm0
- punpckhbw mm3, mm0
+ punpckhbw mm2, mm0
+ punpckhbw mm3, mm0
- movq mm6, mm2
- paddusw mm2, mm1
- paddusw mm2, mm3
+ movq mm6, mm2
+ paddusw mm2, mm1
+ paddusw mm2, mm3
- movq [ebx+esi*2], mm4
+ movq [ebx+esi*2], mm4
- psrlw mm2, 1
- psllq mm2, 8
- por mm2, mm6
+ psrlw mm2, 1
+ psllq mm2, 8
+ por mm2, mm6
- add esi, 0x08
- cmp esi, [edx].HALF_WIDTH_D8
- movq [ebx+esi*2-8], mm2
- jl convyuv444
+ add esi, 0x08
+ cmp esi, [edx].HALF_WIDTH_D8
+ movq [ebx+esi*2-8], mm2
+ jl convyuv444
- movq mm2, mm7
- punpcklbw mm2, mm0
- movq mm3, mm2
+ movq mm2, mm7
+ punpcklbw mm2, mm0
+ movq mm3, mm2
- psllq mm2, 8
- por mm2, mm3
+ psllq mm2, 8
+ por mm2, mm3
- movq [ebx+esi*2], mm2
+ movq [ebx+esi*2], mm2
- punpckhbw mm7, mm0
- movq mm6, mm7
+ punpckhbw mm7, mm0
+ movq mm6, mm7
- psllq mm6, 8
- por mm6, mm7
+ psllq mm6, 8
+ por mm6, mm7
- movq [ebx+esi*2+8], mm6
+ movq [ebx+esi*2+8], mm6
- add eax, [edx].HALF_WIDTH
- add ebx, [edx].Coded_Picture_Width
- dec edi
- cmp edi, 0x00
- jg convyuv444init
- }
+ add eax, [edx].HALF_WIDTH
+ add ebx, [edx].Coded_Picture_Width
+ dec edi
+ cmp edi, 0x00
+ jg convyuv444init
+ }
}
void CMPEG2Dec::conv420to422(unsigned char *src, unsigned char *dst, int frame_type)
{
- if (frame_type)
- {
- __asm
- {
- push ebp
- mov eax, [src]
- mov ebx, [dst]
- mov ebp, this
- mov ecx, ebx
- add ecx, ds:[ebp].HALF_WIDTH
- mov esi, 0x00
- movq mm3, [mmmask_0003]
- pxor mm0, mm0
- movq mm4, [mmmask_0002]
-
- mov edx, eax
- add edx, ds:[ebp].HALF_WIDTH
-convyuv422topp:
- movd mm1, [eax+esi]
- movd mm2, [edx+esi]
- movd [ebx+esi], mm1
- punpcklbw mm1, mm0
- pmullw mm1, mm3
- paddusw mm1, mm4
- punpcklbw mm2, mm0
- paddusw mm2, mm1
- psrlw mm2, 0x02
- packuswb mm2, mm0
-
- add esi, 0x04
- cmp esi, ds:[ebp].HALF_WIDTH
- movd [ecx+esi-4], mm2
- jl convyuv422topp
-
- add eax, ds:[ebp].HALF_WIDTH
- add ebx, ds:[ebp].Coded_Picture_Width
- add ecx, ds:[ebp].Coded_Picture_Width
- mov esi, 0x00
-
- mov edi, ds:[ebp].PROGRESSIVE_HEIGHT
-convyuv422p:
- movd mm1, [eax+esi]
-
- punpcklbw mm1, mm0
- mov edx, eax
-
- pmullw mm1, mm3
- sub edx, ds:[ebp].HALF_WIDTH
-
- movd mm5, [edx+esi]
- movd mm2, [edx+esi]
-
- punpcklbw mm5, mm0
- punpcklbw mm2, mm0
- paddusw mm5, mm1
- paddusw mm2, mm1
- paddusw mm5, mm4
- paddusw mm2, mm4
- psrlw mm5, 0x02
- psrlw mm2, 0x02
- packuswb mm5, mm0
- packuswb mm2, mm0
-
- mov edx, eax
- add edx, ds:[ebp].HALF_WIDTH
- add esi, 0x04
- cmp esi, ds:[ebp].HALF_WIDTH
- movd [ebx+esi-4], mm5
- movd [ecx+esi-4], mm2
-
- jl convyuv422p
-
- add eax, ds:[ebp].HALF_WIDTH
- add ebx, ds:[ebp].Coded_Picture_Width
- add ecx, ds:[ebp].Coded_Picture_Width
- mov esi, 0x00
- dec edi
- cmp edi, 0x00
- jg convyuv422p
-
- mov edx, eax
- sub edx, ds:[ebp].HALF_WIDTH
-convyuv422bottomp:
- movd mm1, [eax+esi]
- movd mm5, [edx+esi]
- punpcklbw mm5, mm0
- movd [ecx+esi], mm1
-
- punpcklbw mm1, mm0
- pmullw mm1, mm3
- paddusw mm5, mm1
- paddusw mm5, mm4
- psrlw mm5, 0x02
- packuswb mm5, mm0
-
- add esi, 0x04
- cmp esi, ds:[ebp].HALF_WIDTH
- movd [ebx+esi-4], mm5
- jl convyuv422bottomp
- pop ebp
- }
- }
- else
- {
- __asm
- {
- push ebp
- mov eax, [src]
- mov ecx, [dst]
- mov ebp, this
- mov esi, 0x00
- pxor mm0, mm0
- movq mm3, [mmmask_0003]
- movq mm4, [mmmask_0004]
- movq mm5, [mmmask_0005]
-
-convyuv422topi:
- movd mm1, [eax+esi]
- mov ebx, eax
- add ebx, ds:[ebp].HALF_WIDTH
- movd mm2, [ebx+esi]
- movd [ecx+esi], mm1
- punpcklbw mm1, mm0
- movq mm6, mm1
- pmullw mm1, mm3
-
- punpcklbw mm2, mm0
- movq mm7, mm2
- pmullw mm2, mm5
- paddusw mm2, mm1
- paddusw mm2, mm4
- psrlw mm2, 0x03
- packuswb mm2, mm0
-
- mov edx, ecx
- add edx, ds:[ebp].HALF_WIDTH
- pmullw mm6, mm5
- movd [edx+esi], mm2
-
- add ebx, ds:[ebp].HALF_WIDTH
- movd mm2, [ebx+esi]
- punpcklbw mm2, mm0
- pmullw mm2, mm3
- paddusw mm2, mm6
- paddusw mm2, mm4
- psrlw mm2, 0x03
- packuswb mm2, mm0
-
- add edx, ds:[ebp].HALF_WIDTH
- add ebx, ds:[ebp].HALF_WIDTH
- pmullw mm7, [mmmask_0007]
- movd [edx+esi], mm2
-
- movd mm2, [ebx+esi]
- punpcklbw mm2, mm0
- paddusw mm2, mm7
- paddusw mm2, mm4
- psrlw mm2, 0x03
- packuswb mm2, mm0
-
- add edx, ds:[ebp].HALF_WIDTH
- add esi, 0x04
- cmp esi, ds:[ebp].HALF_WIDTH
- movd [edx+esi-4], mm2
-
- jl convyuv422topi
-
- add eax, ds:[ebp].Coded_Picture_Width
- add ecx, ds:[ebp].DOUBLE_WIDTH
- mov esi, 0x00
-
- mov edi, ds:[ebp].INTERLACED_HEIGHT
-convyuv422i:
- movd mm1, [eax+esi]
- punpcklbw mm1, mm0
- movq mm6, mm1
- mov ebx, eax
- sub ebx, ds:[ebp].Coded_Picture_Width
- movd mm3, [ebx+esi]
- pmullw mm1, [mmmask_0007]
- punpcklbw mm3, mm0
- paddusw mm3, mm1
- paddusw mm3, mm4
- psrlw mm3, 0x03
- packuswb mm3, mm0
-
- add ebx, ds:[ebp].HALF_WIDTH
- movq mm1, [ebx+esi]
- add ebx, ds:[ebp].Coded_Picture_Width
- movd [ecx+esi], mm3
-
- movq mm3, [mmmask_0003]
- movd mm2, [ebx+esi]
-
- punpcklbw mm1, mm0
- pmullw mm1, mm3
- punpcklbw mm2, mm0
- movq mm7, mm2
- pmullw mm2, mm5
- paddusw mm2, mm1
- paddusw mm2, mm4
- psrlw mm2, 0x03
- packuswb mm2, mm0
-
- pmullw mm6, mm5
- mov edx, ecx
- add edx, ds:[ebp].HALF_WIDTH
- movd [edx+esi], mm2
-
- add ebx, ds:[ebp].HALF_WIDTH
- movd mm2, [ebx+esi]
- punpcklbw mm2, mm0
- pmullw mm2, mm3
- paddusw mm2, mm6
- paddusw mm2, mm4
- psrlw mm2, 0x03
- packuswb mm2, mm0
-
- pmullw mm7, [mmmask_0007]
- add edx, ds:[ebp].HALF_WIDTH
- add ebx, ds:[ebp].HALF_WIDTH
- movd [edx+esi], mm2
-
- movd mm2, [ebx+esi]
- punpcklbw mm2, mm0
- paddusw mm2, mm7
- paddusw mm2, mm4
- psrlw mm2, 0x03
- packuswb mm2, mm0
-
- add edx, ds:[ebp].HALF_WIDTH
- add esi, 0x04
- cmp esi, ds:[ebp].HALF_WIDTH
- movd [edx+esi-4], mm2
-
- jl convyuv422i
- add eax, ds:[ebp].Coded_Picture_Width
- add ecx, ds:[ebp].DOUBLE_WIDTH
- mov esi, 0x00
- dec edi
- cmp edi, 0x00
- jg convyuv422i
-
-convyuv422bottomi:
- movd mm1, [eax+esi]
- movq mm6, mm1
- punpcklbw mm1, mm0
- mov ebx, eax
- sub ebx, ds:[ebp].Coded_Picture_Width
- movd mm3, [ebx+esi]
- punpcklbw mm3, mm0
- pmullw mm1, [mmmask_0007]
- paddusw mm3, mm1
- paddusw mm3, mm4
- psrlw mm3, 0x03
- packuswb mm3, mm0
-
- add ebx, ds:[ebp].HALF_WIDTH
- movq mm1, [ebx+esi]
- punpcklbw mm1, mm0
- movd [ecx+esi], mm3
-
- pmullw mm1, [mmmask_0003]
- add ebx, ds:[ebp].Coded_Picture_Width
- movd mm2, [ebx+esi]
- punpcklbw mm2, mm0
- movq mm7, mm2
- pmullw mm2, mm5
- paddusw mm2, mm1
- paddusw mm2, mm4
- psrlw mm2, 0x03
- packuswb mm2, mm0
-
- mov edx, ecx
- add edx, ds:[ebp].HALF_WIDTH
- pmullw mm7, [mmmask_0007]
- movd [edx+esi], mm2
-
- add edx, ds:[ebp].HALF_WIDTH
- movd [edx+esi], mm6
-
- punpcklbw mm6, mm0
- paddusw mm6, mm7
- paddusw mm6, mm4
- psrlw mm6, 0x03
- packuswb mm6, mm0
-
- add edx, ds:[ebp].HALF_WIDTH
- add esi, 0x04
- cmp esi, ds:[ebp].HALF_WIDTH
- movd [edx+esi-4], mm6
-
- jl convyuv422bottomi
- pop ebp
- }
- }
+ if(frame_type)
+ {
+ __asm
+ {
+ push ebp
+ mov eax, [src]
+ mov ebx, [dst]
+ mov ebp, this
+ mov ecx, ebx
+ add ecx, ds:[ebp].HALF_WIDTH
+ mov esi, 0x00
+ movq mm3, [mmmask_0003]
+ pxor mm0, mm0
+ movq mm4, [mmmask_0002]
+
+ mov edx, eax
+ add edx, ds:[ebp].HALF_WIDTH
+ convyuv422topp:
+ movd mm1, [eax+esi]
+ movd mm2, [edx+esi]
+ movd [ebx+esi], mm1
+ punpcklbw mm1, mm0
+ pmullw mm1, mm3
+ paddusw mm1, mm4
+ punpcklbw mm2, mm0
+ paddusw mm2, mm1
+ psrlw mm2, 0x02
+ packuswb mm2, mm0
+
+ add esi, 0x04
+ cmp esi, ds:[ebp].HALF_WIDTH
+ movd [ecx+esi-4], mm2
+ jl convyuv422topp
+
+ add eax, ds:[ebp].HALF_WIDTH
+ add ebx, ds:[ebp].Coded_Picture_Width
+ add ecx, ds:[ebp].Coded_Picture_Width
+ mov esi, 0x00
+
+ mov edi, ds:[ebp].PROGRESSIVE_HEIGHT
+ convyuv422p:
+ movd mm1, [eax+esi]
+
+ punpcklbw mm1, mm0
+ mov edx, eax
+
+ pmullw mm1, mm3
+ sub edx, ds:[ebp].HALF_WIDTH
+
+ movd mm5, [edx+esi]
+ movd mm2, [edx+esi]
+
+ punpcklbw mm5, mm0
+ punpcklbw mm2, mm0
+ paddusw mm5, mm1
+ paddusw mm2, mm1
+ paddusw mm5, mm4
+ paddusw mm2, mm4
+ psrlw mm5, 0x02
+ psrlw mm2, 0x02
+ packuswb mm5, mm0
+ packuswb mm2, mm0
+
+ mov edx, eax
+ add edx, ds:[ebp].HALF_WIDTH
+ add esi, 0x04
+ cmp esi, ds:[ebp].HALF_WIDTH
+ movd [ebx+esi-4], mm5
+ movd [ecx+esi-4], mm2
+
+ jl convyuv422p
+
+ add eax, ds:[ebp].HALF_WIDTH
+ add ebx, ds:[ebp].Coded_Picture_Width
+ add ecx, ds:[ebp].Coded_Picture_Width
+ mov esi, 0x00
+ dec edi
+ cmp edi, 0x00
+ jg convyuv422p
+
+ mov edx, eax
+ sub edx, ds:[ebp].HALF_WIDTH
+ convyuv422bottomp:
+ movd mm1, [eax+esi]
+ movd mm5, [edx+esi]
+ punpcklbw mm5, mm0
+ movd [ecx+esi], mm1
+
+ punpcklbw mm1, mm0
+ pmullw mm1, mm3
+ paddusw mm5, mm1
+ paddusw mm5, mm4
+ psrlw mm5, 0x02
+ packuswb mm5, mm0
+
+ add esi, 0x04
+ cmp esi, ds:[ebp].HALF_WIDTH
+ movd [ebx+esi-4], mm5
+ jl convyuv422bottomp
+ pop ebp
+ }
+ }
+ else
+ {
+ __asm
+ {
+ push ebp
+ mov eax, [src]
+ mov ecx, [dst]
+ mov ebp, this
+ mov esi, 0x00
+ pxor mm0, mm0
+ movq mm3, [mmmask_0003]
+ movq mm4, [mmmask_0004]
+ movq mm5, [mmmask_0005]
+
+ convyuv422topi:
+ movd mm1, [eax+esi]
+ mov ebx, eax
+ add ebx, ds:[ebp].HALF_WIDTH
+ movd mm2, [ebx+esi]
+ movd [ecx+esi], mm1
+ punpcklbw mm1, mm0
+ movq mm6, mm1
+ pmullw mm1, mm3
+
+ punpcklbw mm2, mm0
+ movq mm7, mm2
+ pmullw mm2, mm5
+ paddusw mm2, mm1
+ paddusw mm2, mm4
+ psrlw mm2, 0x03
+ packuswb mm2, mm0
+
+ mov edx, ecx
+ add edx, ds:[ebp].HALF_WIDTH
+ pmullw mm6, mm5
+ movd [edx+esi], mm2
+
+ add ebx, ds:[ebp].HALF_WIDTH
+ movd mm2, [ebx+esi]
+ punpcklbw mm2, mm0
+ pmullw mm2, mm3
+ paddusw mm2, mm6
+ paddusw mm2, mm4
+ psrlw mm2, 0x03
+ packuswb mm2, mm0
+
+ add edx, ds:[ebp].HALF_WIDTH
+ add ebx, ds:[ebp].HALF_WIDTH
+ pmullw mm7, [mmmask_0007]
+ movd [edx+esi], mm2
+
+ movd mm2, [ebx+esi]
+ punpcklbw mm2, mm0
+ paddusw mm2, mm7
+ paddusw mm2, mm4
+ psrlw mm2, 0x03
+ packuswb mm2, mm0
+
+ add edx, ds:[ebp].HALF_WIDTH
+ add esi, 0x04
+ cmp esi, ds:[ebp].HALF_WIDTH
+ movd [edx+esi-4], mm2
+
+ jl convyuv422topi
+
+ add eax, ds:[ebp].Coded_Picture_Width
+ add ecx, ds:[ebp].DOUBLE_WIDTH
+ mov esi, 0x00
+
+ mov edi, ds:[ebp].INTERLACED_HEIGHT
+ convyuv422i:
+ movd mm1, [eax+esi]
+ punpcklbw mm1, mm0
+ movq mm6, mm1
+ mov ebx, eax
+ sub ebx, ds:[ebp].Coded_Picture_Width
+ movd mm3, [ebx+esi]
+ pmullw mm1, [mmmask_0007]
+ punpcklbw mm3, mm0
+ paddusw mm3, mm1
+ paddusw mm3, mm4
+ psrlw mm3, 0x03
+ packuswb mm3, mm0
+
+ add ebx, ds:[ebp].HALF_WIDTH
+ movq mm1, [ebx+esi]
+ add ebx, ds:[ebp].Coded_Picture_Width
+ movd [ecx+esi], mm3
+
+ movq mm3, [mmmask_0003]
+ movd mm2, [ebx+esi]
+
+ punpcklbw mm1, mm0
+ pmullw mm1, mm3
+ punpcklbw mm2, mm0
+ movq mm7, mm2
+ pmullw mm2, mm5
+ paddusw mm2, mm1
+ paddusw mm2, mm4
+ psrlw mm2, 0x03
+ packuswb mm2, mm0
+
+ pmullw mm6, mm5
+ mov edx, ecx
+ add edx, ds:[ebp].HALF_WIDTH
+ movd [edx+esi], mm2
+
+ add ebx, ds:[ebp].HALF_WIDTH
+ movd mm2, [ebx+esi]
+ punpcklbw mm2, mm0
+ pmullw mm2, mm3
+ paddusw mm2, mm6
+ paddusw mm2, mm4
+ psrlw mm2, 0x03
+ packuswb mm2, mm0
+
+ pmullw mm7, [mmmask_0007]
+ add edx, ds:[ebp].HALF_WIDTH
+ add ebx, ds:[ebp].HALF_WIDTH
+ movd [edx+esi], mm2
+
+ movd mm2, [ebx+esi]
+ punpcklbw mm2, mm0
+ paddusw mm2, mm7
+ paddusw mm2, mm4
+ psrlw mm2, 0x03
+ packuswb mm2, mm0
+
+ add edx, ds:[ebp].HALF_WIDTH
+ add esi, 0x04
+ cmp esi, ds:[ebp].HALF_WIDTH
+ movd [edx+esi-4], mm2
+
+ jl convyuv422i
+ add eax, ds:[ebp].Coded_Picture_Width
+ add ecx, ds:[ebp].DOUBLE_WIDTH
+ mov esi, 0x00
+ dec edi
+ cmp edi, 0x00
+ jg convyuv422i
+
+ convyuv422bottomi:
+ movd mm1, [eax+esi]
+ movq mm6, mm1
+ punpcklbw mm1, mm0
+ mov ebx, eax
+ sub ebx, ds:[ebp].Coded_Picture_Width
+ movd mm3, [ebx+esi]
+ punpcklbw mm3, mm0
+ pmullw mm1, [mmmask_0007]
+ paddusw mm3, mm1
+ paddusw mm3, mm4
+ psrlw mm3, 0x03
+ packuswb mm3, mm0
+
+ add ebx, ds:[ebp].HALF_WIDTH
+ movq mm1, [ebx+esi]
+ punpcklbw mm1, mm0
+ movd [ecx+esi], mm3
+
+ pmullw mm1, [mmmask_0003]
+ add ebx, ds:[ebp].Coded_Picture_Width
+ movd mm2, [ebx+esi]
+ punpcklbw mm2, mm0
+ movq mm7, mm2
+ pmullw mm2, mm5
+ paddusw mm2, mm1
+ paddusw mm2, mm4
+ psrlw mm2, 0x03
+ packuswb mm2, mm0
+
+ mov edx, ecx
+ add edx, ds:[ebp].HALF_WIDTH
+ pmullw mm7, [mmmask_0007]
+ movd [edx+esi], mm2
+
+ add edx, ds:[ebp].HALF_WIDTH
+ movd [edx+esi], mm6
+
+ punpcklbw mm6, mm0
+ paddusw mm6, mm7
+ paddusw mm6, mm4
+ psrlw mm6, 0x03
+ packuswb mm6, mm0
+
+ add edx, ds:[ebp].HALF_WIDTH
+ add esi, 0x04
+ cmp esi, ds:[ebp].HALF_WIDTH
+ movd [edx+esi-4], mm6
+
+ jl convyuv422bottomi
+ pop ebp
+ }
+ }
}
void CMPEG2Dec::conv444toRGB24(unsigned char *py, unsigned char *pu, unsigned char *pv, unsigned char *dst, int pitch)
{
- int PWIDTH = pitch - DSTBYTES;
-
- py += CLIP_STEP;
- pu += CLIP_STEP;
- pv += CLIP_STEP;
-
- int Clip_Height = this->Clip_Height;
- __int64 RGB_Offset = this->RGB_Offset;
- __int64 RGB_Scale = this->RGB_Scale;
- __int64 RGB_CBU = this->RGB_CBU;
- __int64 RGB_CRV = this->RGB_CRV;
- __int64 RGB_CGX = this->RGB_CGX;
- int Clip_Width = this->Clip_Width;
- int Coded_Picture_Width = this->Coded_Picture_Width;
-
- __asm
- {
- mov eax, [py]
- mov ebx, [pu]
- mov ecx, [pv]
- mov edx, [dst]
- mov edi, Clip_Height
- mov esi, 0x00
- pxor mm0, mm0
-
-convRGB24:
- movd mm1, [eax+esi]
- movd mm3, [ebx+esi]
- punpcklbw mm1, mm0
- punpcklbw mm3, mm0
- movd mm5, [ecx+esi]
- punpcklbw mm5, mm0
- movq mm7, [mmmask_0128]
- psubw mm3, mm7
- psubw mm5, mm7
-
- psubw mm1, RGB_Offset
- movq mm2, mm1
- movq mm7, [mmmask_0001]
- punpcklwd mm1, mm7
- punpckhwd mm2, mm7
- movq mm7, RGB_Scale
- pmaddwd mm1, mm7
- pmaddwd mm2, mm7
-
- movq mm4, mm3
- punpcklwd mm3, mm0
- punpckhwd mm4, mm0
- movq mm7, RGB_CBU
- pmaddwd mm3, mm7
- pmaddwd mm4, mm7
- paddd mm3, mm1
- paddd mm4, mm2
- psrld mm3, 13
- psrld mm4, 13
- packuswb mm3, mm0
- packuswb mm4, mm0
-
- movq mm6, mm5
- punpcklwd mm5, mm0
- punpckhwd mm6, mm0
- movq mm7, RGB_CRV
- pmaddwd mm5, mm7
- pmaddwd mm6, mm7
- paddd mm5, mm1
- paddd mm6, mm2
- psrld mm5, 13
- psrld mm6, 13
- packuswb mm5, mm0
- packuswb mm6, mm0
-
- punpcklbw mm3, mm5
- punpcklbw mm4, mm6
- movq mm5, mm3
- movq mm6, mm4
- psrlq mm5, 16
- psrlq mm6, 16
- por mm3, mm5
- por mm4, mm6
-
- movd mm5, [ebx+esi]
- movd mm6, [ecx+esi]
- punpcklbw mm5, mm0
- punpcklbw mm6, mm0
- movq mm7, [mmmask_0128]
- psubw mm5, mm7
- psubw mm6, mm7
-
- movq mm7, mm6
- punpcklwd mm6, mm5
- punpckhwd mm7, mm5
- movq mm5, RGB_CGX
- pmaddwd mm6, mm5
- pmaddwd mm7, mm5
- paddd mm6, mm1
- paddd mm7, mm2
-
- psrld mm6, 13
- psrld mm7, 13
- packuswb mm6, mm0
- packuswb mm7, mm0
-
- punpcklbw mm3, mm6
- punpcklbw mm4, mm7
-
- movq mm1, mm3
- movq mm5, mm4
- movq mm6, mm4
-
- psrlq mm1, 32
- psllq mm1, 24
- por mm1, mm3
-
- psrlq mm3, 40
- psllq mm6, 16
- por mm3, mm6
- movd [edx], mm1
-
- psrld mm4, 16
- psrlq mm5, 24
- por mm5, mm4
- movd [edx+4], mm3
-
- add edx, 0x0c
- add esi, 0x04
- cmp esi, Clip_Width
- movd [edx-4], mm5
-
- jl convRGB24
-
- add eax, Coded_Picture_Width
- add ebx, Coded_Picture_Width
- add ecx, Coded_Picture_Width
- add edx, PWIDTH
- mov esi, 0x00
- dec edi
- cmp edi, 0x00
- jg convRGB24
-
- emms
- }
+ int PWIDTH = pitch - DSTBYTES;
+
+ py += CLIP_STEP;
+ pu += CLIP_STEP;
+ pv += CLIP_STEP;
+
+ int Clip_Height = this->Clip_Height;
+ __int64 RGB_Offset = this->RGB_Offset;
+ __int64 RGB_Scale = this->RGB_Scale;
+ __int64 RGB_CBU = this->RGB_CBU;
+ __int64 RGB_CRV = this->RGB_CRV;
+ __int64 RGB_CGX = this->RGB_CGX;
+ int Clip_Width = this->Clip_Width;
+ int Coded_Picture_Width = this->Coded_Picture_Width;
+
+ __asm
+ {
+ mov eax, [py]
+ mov ebx, [pu]
+ mov ecx, [pv]
+ mov edx, [dst]
+ mov edi, Clip_Height
+ mov esi, 0x00
+ pxor mm0, mm0
+
+ convRGB24:
+ movd mm1, [eax+esi]
+ movd mm3, [ebx+esi]
+ punpcklbw mm1, mm0
+ punpcklbw mm3, mm0
+ movd mm5, [ecx+esi]
+ punpcklbw mm5, mm0
+ movq mm7, [mmmask_0128]
+ psubw mm3, mm7
+ psubw mm5, mm7
+
+ psubw mm1, RGB_Offset
+ movq mm2, mm1
+ movq mm7, [mmmask_0001]
+ punpcklwd mm1, mm7
+ punpckhwd mm2, mm7
+ movq mm7, RGB_Scale
+ pmaddwd mm1, mm7
+ pmaddwd mm2, mm7
+
+ movq mm4, mm3
+ punpcklwd mm3, mm0
+ punpckhwd mm4, mm0
+ movq mm7, RGB_CBU
+ pmaddwd mm3, mm7
+ pmaddwd mm4, mm7
+ paddd mm3, mm1
+ paddd mm4, mm2
+ psrld mm3, 13
+ psrld mm4, 13
+ packuswb mm3, mm0
+ packuswb mm4, mm0
+
+ movq mm6, mm5
+ punpcklwd mm5, mm0
+ punpckhwd mm6, mm0
+ movq mm7, RGB_CRV
+ pmaddwd mm5, mm7
+ pmaddwd mm6, mm7
+ paddd mm5, mm1
+ paddd mm6, mm2
+ psrld mm5, 13
+ psrld mm6, 13
+ packuswb mm5, mm0
+ packuswb mm6, mm0
+
+ punpcklbw mm3, mm5
+ punpcklbw mm4, mm6
+ movq mm5, mm3
+ movq mm6, mm4
+ psrlq mm5, 16
+ psrlq mm6, 16
+ por mm3, mm5
+ por mm4, mm6
+
+ movd mm5, [ebx+esi]
+ movd mm6, [ecx+esi]
+ punpcklbw mm5, mm0
+ punpcklbw mm6, mm0
+ movq mm7, [mmmask_0128]
+ psubw mm5, mm7
+ psubw mm6, mm7
+
+ movq mm7, mm6
+ punpcklwd mm6, mm5
+ punpckhwd mm7, mm5
+ movq mm5, RGB_CGX
+ pmaddwd mm6, mm5
+ pmaddwd mm7, mm5
+ paddd mm6, mm1
+ paddd mm7, mm2
+
+ psrld mm6, 13
+ psrld mm7, 13
+ packuswb mm6, mm0
+ packuswb mm7, mm0
+
+ punpcklbw mm3, mm6
+ punpcklbw mm4, mm7
+
+ movq mm1, mm3
+ movq mm5, mm4
+ movq mm6, mm4
+
+ psrlq mm1, 32
+ psllq mm1, 24
+ por mm1, mm3
+
+ psrlq mm3, 40
+ psllq mm6, 16
+ por mm3, mm6
+ movd [edx], mm1
+
+ psrld mm4, 16
+ psrlq mm5, 24
+ por mm5, mm4
+ movd [edx+4], mm3
+
+ add edx, 0x0c
+ add esi, 0x04
+ cmp esi, Clip_Width
+ movd [edx-4], mm5
+
+ jl convRGB24
+
+ add eax, Coded_Picture_Width
+ add ebx, Coded_Picture_Width
+ add ecx, Coded_Picture_Width
+ add edx, PWIDTH
+ mov esi, 0x00
+ dec edi
+ cmp edi, 0x00
+ jg convRGB24
+
+ emms
+ }
}
// YUV 4:2:2 Format:
// YUYV YUYV ...
void CMPEG2Dec::conv422toYUY2(unsigned char *py, unsigned char *pu, unsigned char *pv, unsigned char *dst, int pitch)
{
- py += CLIP_STEP;
- pu += CLIP_STEP;
- pv += CLIP_STEP;
-
- int y = this->Clip_Height;
- int Clip_Width_2 = this->Clip_Width / 2;
- int Coded_Picture_Width = this->Coded_Picture_Width;
- int Coded_Picture_Width_2 = this->Coded_Picture_Width / 2;
-
- __asm
- {
- emms
- mov eax, [py]
- mov ebx, [pu]
- mov ecx, [pv]
- mov edx, [dst]
- mov edi, Clip_Width_2
- yloop:
- xor esi, esi
- xloop:
- movd mm1, [eax+esi*2] ;0000YYYY
- movd mm2, [ebx+esi] ;0000UUUU
- movd mm3, [ecx+esi] ;0000VVVV
- ;interleave this to VYUYVYUY
- punpcklbw mm2, mm3 ;VUVUVUVU
- punpcklbw mm1, mm2 ;VYUYVYUY
- movq [edx+esi*4], mm1
- movd mm1, [eax+esi*2+4] ;0000YYYY
- punpckhdq mm2, mm2 ;xxxxVUVU
- punpcklbw mm1, mm2 ;VYUYVYUY
- movq [edx+esi*4+8], mm1
- add esi, 4
- cmp esi, edi
- jb xloop
- add edx, pitch
- add eax, Coded_Picture_Width
- add ebx, Coded_Picture_Width_2
- add ecx, Coded_Picture_Width_2
- dec y
- jnz yloop
- emms
- }
+ py += CLIP_STEP;
+ pu += CLIP_STEP;
+ pv += CLIP_STEP;
+
+ int y = this->Clip_Height;
+ int Clip_Width_2 = this->Clip_Width / 2;
+ int Coded_Picture_Width = this->Coded_Picture_Width;
+ int Coded_Picture_Width_2 = this->Coded_Picture_Width / 2;
+
+ __asm
+ {
+ emms
+ mov eax, [py]
+ mov ebx, [pu]
+ mov ecx, [pv]
+ mov edx, [dst]
+ mov edi, Clip_Width_2
+ yloop:
+ xor esi, esi
+ xloop:
+ movd mm1, [eax+esi*2] ;
+ 0000YYYY
+ movd mm2, [ebx+esi] ;
+ 0000UUUU
+ movd mm3, [ecx+esi] ;
+ 0000VVVV
+ ;
+ interleave this to VYUYVYUY
+ punpcklbw mm2, mm3 ;
+ VUVUVUVU
+ punpcklbw mm1, mm2 ;
+ VYUYVYUY
+ movq [edx+esi*4], mm1
+ movd mm1, [eax+esi*2+4] ;
+ 0000YYYY
+ punpckhdq mm2, mm2 ;
+ xxxxVUVU
+ punpcklbw mm1, mm2 ;
+ VYUYVYUY
+ movq [edx+esi*4+8], mm1
+ add esi, 4
+ cmp esi, edi
+ jb xloop
+ add edx, pitch
+ add eax, Coded_Picture_Width
+ add ebx, Coded_Picture_Width_2
+ add ecx, Coded_Picture_Width_2
+ dec y
+ jnz yloop
+ emms
+ }
}
//
// codec
//
-static const int ChromaFormat[4] = {
- 0, 6, 8, 12
+static const int ChromaFormat[4] =
+{
+ 0, 6, 8, 12
};
CMPEG2Dec::CMPEG2Dec()
{
- VF_File = 0;
- VF_FrameLimit = VF_FrameBound = VF_GOPLimit = VF_GOPNow = VF_GOPSize =
- VF_OldFrame = VF_OldRef = 0;
- VF_FrameSize = VF_FrameRate = 0;
- memset(Rdbfr, 0, sizeof(Rdbfr));
- Rdptr = Rdmax = 0;
- CurrentBfr = NextBfr = BitsLeft = Val = Read = 0;
- Fault_Flag = File_Flag = File_Limit = FO_Flag = IDCT_Flag = SystemStream_Flag = 0;
- Luminance_Flag = Resize_Flag = KeyOp_Flag = lfsr0 = lfsr1 = 0;
- BufferOp = 0;
- memset(intra_quantizer_matrix, 0, sizeof(intra_quantizer_matrix));
- memset(non_intra_quantizer_matrix, 0, sizeof(non_intra_quantizer_matrix));
- memset(chroma_intra_quantizer_matrix, 0, sizeof(chroma_intra_quantizer_matrix));
- memset(chroma_non_intra_quantizer_matrix, 0, sizeof(chroma_non_intra_quantizer_matrix));
- load_intra_quantizer_matrix =
- load_non_intra_quantizer_matrix =
- load_chroma_intra_quantizer_matrix =
- load_chroma_non_intra_quantizer_matrix = 0;
- q_scale_type =
- alternate_scan =
- quantizer_scale = 0;
-
- int i;
- for (i=0; i<MAX_FILE_NUMBER; i++) Infilename[i] = NULL;
- for (i=0; i<8; i++) p_block[i] = block[i] = NULL;
- p_fTempArray = fTempArray = NULL;
- for (i=0; i<3; i++) backward_reference_frame[i] = forward_reference_frame[i] = auxframe[i] = NULL;
- lum = NULL;
- u422 = v422 = u444 = v444 = dstFrame = NULL;
- hLibrary = NULL;
-
- CheckCPU();
+ VF_File = 0;
+ VF_FrameLimit = VF_FrameBound = VF_GOPLimit = VF_GOPNow = VF_GOPSize =
+ VF_OldFrame = VF_OldRef = 0;
+ VF_FrameSize = VF_FrameRate = 0;
+ memset(Rdbfr, 0, sizeof(Rdbfr));
+ Rdptr = Rdmax = 0;
+ CurrentBfr = NextBfr = BitsLeft = Val = Read = 0;
+ Fault_Flag = File_Flag = File_Limit = FO_Flag = IDCT_Flag = SystemStream_Flag = 0;
+ Luminance_Flag = Resize_Flag = KeyOp_Flag = lfsr0 = lfsr1 = 0;
+ BufferOp = 0;
+ memset(intra_quantizer_matrix, 0, sizeof(intra_quantizer_matrix));
+ memset(non_intra_quantizer_matrix, 0, sizeof(non_intra_quantizer_matrix));
+ memset(chroma_intra_quantizer_matrix, 0, sizeof(chroma_intra_quantizer_matrix));
+ memset(chroma_non_intra_quantizer_matrix, 0, sizeof(chroma_non_intra_quantizer_matrix));
+ load_intra_quantizer_matrix =
+ load_non_intra_quantizer_matrix =
+ load_chroma_intra_quantizer_matrix =
+ load_chroma_non_intra_quantizer_matrix = 0;
+ q_scale_type =
+ alternate_scan =
+ quantizer_scale = 0;
+
+ int i;
+ for(i = 0; i < MAX_FILE_NUMBER; i++) Infilename[i] = NULL;
+ for(i = 0; i < 8; i++) p_block[i] = block[i] = NULL;
+ p_fTempArray = fTempArray = NULL;
+ for(i = 0; i < 3; i++) backward_reference_frame[i] = forward_reference_frame[i] = auxframe[i] = NULL;
+ lum = NULL;
+ u422 = v422 = u444 = v444 = dstFrame = NULL;
+ hLibrary = NULL;
+
+ CheckCPU();
}
static char* myfgets(char* buff, int len, FILE* file)
{
- char* ret = buff;
+ char* ret = buff;
- ret[0] = 0;
-
- while(ret = fgets(buff, len, file))
- {
- while(isspace(*ret)) ret++;
- if(*ret) break;
- }
+ ret[0] = 0;
- return(ret);
+ while(ret = fgets(buff, len, file))
+ {
+ while(isspace(*ret)) ret++;
+ if(*ret) break;
+ }
+
+ return(ret);
}
int CMPEG2Dec::Open(LPCTSTR path, DstFormat dstFormat)
{
- m_dstFormat = dstFormat;
- char ID[19], PASS[19] = "DVD2AVIProjectFile";
- DWORD i, j, size, code, type, tff, rff, film, ntsc, gop, top, bottom, mapping;
- int repeat_on, repeat_off, repeat_init;
- int Clip_Top, Clip_Bottom, Clip_Left, Clip_Right, Squeeze_Width, Squeeze_Height;
-
- HKEY key; DWORD value = REG_SZ; DWORD length = 256;
- char *ext, buffer[256];
-
- CMPEG2Dec* out = this;
-
- out->VF_File = _tfopen(path, _T("r"));
- if (out->VF_File==NULL)
- return 0;
- if (fgets(ID, 19, out->VF_File)==NULL)
- return 0;
- if (strcmp(ID, PASS))
- return 0;
-
- // load DLL
- if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\VFPlugin", 0, KEY_ALL_ACCESS, &key)==ERROR_SUCCESS)
- {
- RegQueryValueExA(key, "DVD2AVI", NULL, &value, (unsigned char*)buffer, &length);
-
- ext = strrchr(buffer, '\\');
- sprintf(buffer + (int)(ext-buffer) + 1, "OpenDVD.dll");
- RegCloseKey(key);
- }
-
- if ((hLibrary = LoadLibraryA(buffer)) != NULL)
- BufferOp = (PBufferOp) GetProcAddress(hLibrary, "BufferOp");
-
- for (i=0; i<MAX_FILE_NUMBER; i++)
- Infilename[i] = DNew char[_MAX_PATH];
-
- if(1 != fscanf(out->VF_File, "%d", &File_Limit))
- return 0;
-
- i = File_Limit;
- while (i)
- {
- if(1 != fscanf(out->VF_File, "%d ", &j))
- return 0;
- fgets(Infilename[File_Limit-i], j+1, out->VF_File);
- if ((Infile[File_Limit-i] = _open(Infilename[File_Limit-i], _O_RDONLY | _O_BINARY))==-1)
- return 0;
- i--;
- }
-
- if(3 != sscanf(myfgets(buffer, sizeof(buffer), out->VF_File), "\nStream_Type=%d,%X,%X\n", &SystemStream_Flag, &lfsr0, &lfsr1))
- return 0;
- if (lfsr0 || lfsr1)
- KeyOp_Flag = 1;
- else
- KeyOp_Flag = 0;
-
- if(1 != sscanf(myfgets(buffer, sizeof(buffer), out->VF_File), "iDCT_Algorithm=%d\n", &IDCT_Flag))
- return 0;
-
- switch (IDCT_Flag)
- {
- case IDCT_SSEMMX:
- if (!cpu.ssemmx)
- IDCT_Flag = IDCT_MMX;
- break;
-
- case IDCT_FPU:
- Initialize_FPU_IDCT();
- break;
-
- case IDCT_REF:
- Initialize_REF_IDCT();
- break;
- }
-
- File_Flag = 0;
- _lseeki64(Infile[0], 0, SEEK_SET);
- Initialize_Buffer();
-
- do
- {
- next_start_code();
- code = Get_Bits(32);
- }
- while (code!=SEQUENCE_HEADER_CODE);
-
- sequence_header();
-
- mb_width = (horizontal_size+15)/16;
- mb_height = progressive_sequence ? (vertical_size+15)/16 : 2*((vertical_size+31)/32);
-
- Coded_Picture_Width = 16 * mb_width;
- Coded_Picture_Height = 16 * mb_height;
-
- Chroma_Width = (chroma_format==CHROMA444) ? Coded_Picture_Width : Coded_Picture_Width>>1;
- Chroma_Height = (chroma_format!=CHROMA420) ? Coded_Picture_Height : Coded_Picture_Height>>1;
-
- block_count = ChromaFormat[chroma_format];
-
- for (i=0; i<8; i++)
- {
- p_block[i] = (short *)DNew BYTE[sizeof(short)*64 + 64];
- block[i] = (short *)((long)p_block[i] + 64 - (long)p_block[i]%64);
- }
-
- p_fTempArray = (void *)DNew BYTE[sizeof(float)*128 + 64];
- fTempArray = (void *)((long)p_fTempArray + 64 - (long)p_fTempArray%64);
-
- for (i=0; i<3; i++)
- {
- if (i==0)
- size = Coded_Picture_Width * Coded_Picture_Height;
- else
- size = Chroma_Width * Chroma_Height;
-
- backward_reference_frame[i] = DNew unsigned char[size];
- forward_reference_frame[i] = DNew unsigned char[size];
- auxframe[i] = DNew unsigned char[size];
- }
-
- if(1 != sscanf(myfgets(buffer, sizeof(buffer), out->VF_File), "YUVRGB_Scale=%d\n", &i))
- return 0;
-
- if (i)
- {
- RGB_Scale = 0x1000254310002543;
- RGB_Offset = 0x0010001000100010;
- RGB_CBU = 0x0000408D0000408D;
- RGB_CGX = 0xF377E5FCF377E5FC;
- RGB_CRV = 0x0000331300003313;
- }
- else
- {
- RGB_Scale = 0x1000200010002000;
- RGB_Offset = 0x0000000000000000;
- RGB_CBU = 0x000038B4000038B4;
- RGB_CGX = 0xF4FDE926F4FDE926;
- RGB_CRV = 0x00002CDD00002CDD;
- }
-
- char* tmp = myfgets(buffer, sizeof(buffer), out->VF_File);
- if(2 != sscanf(tmp, "Luminance=%d,%d\n", &i, &j))
- {
- if(2 != sscanf(tmp, "Luminance_Filter=%d,%d\n", &i, &j))
- return 0;
- i=128; j=0;
- }
-
- if (i==128 && j==0)
- Luminance_Flag = 0;
- else
- {
- Luminance_Flag = 1;
- LumGainMask = ((__int64)i<<48) + ((__int64)i<<32) + ((__int64)i<<16) + (__int64)i;
- LumOffsetMask = ((__int64)j<<48) + ((__int64)j<<32) + ((__int64)j<<16) + (__int64)j;
-
- lum = DNew unsigned char[Coded_Picture_Width * Coded_Picture_Height];
- }
-
- if(6 != sscanf(myfgets(buffer, sizeof(buffer), out->VF_File), "Picture_Size=%d,%d,%d,%d,%d,%d\n",
- &Clip_Top, &Clip_Bottom, &Clip_Left, &Clip_Right, &Squeeze_Width, &Squeeze_Height))
- return 0;
-
- Resize_Flag = 0;
- Resize_Width = Clip_Width = Coded_Picture_Width;
- Resize_Height = Clip_Height = Coded_Picture_Height;
- CLIP_AREA = HALF_CLIP_AREA = CLIP_STEP = 0;
-
- if (Clip_Top || Clip_Bottom || Clip_Left || Clip_Right)
- {
- Clip_Width -= Clip_Left+Clip_Right;
- Clip_Height -= Clip_Top+Clip_Bottom;
- Resize_Width = Clip_Width;
- Resize_Height = Clip_Height;
-
- CLIP_AREA = Coded_Picture_Width * Clip_Top;
- HALF_CLIP_AREA = (Coded_Picture_Width>>1) * Clip_Top;
- CLIP_STEP = Coded_Picture_Width * Clip_Top + Clip_Left;
- }
-
- if (Squeeze_Width || Squeeze_Height)
- {
- Resize_Flag = 1;
- Resize_Width -= Squeeze_Width;
- Resize_Height -= Squeeze_Height;
- }
-
- DSTBYTES = Clip_Width * (dstRGB24() ? 3 : 2);
- DSTBYTES2 = DSTBYTES * 2;
- LUM_AREA = Coded_Picture_Width * Clip_Height;
- PROGRESSIVE_HEIGHT = (Coded_Picture_Height>>1) - 2;
- INTERLACED_HEIGHT = (Coded_Picture_Height>>2) - 2;
- HALF_WIDTH = Coded_Picture_Width>>1;
- HALF_WIDTH_D8 = (Coded_Picture_Width>>1) - 8;
- DOUBLE_WIDTH = Coded_Picture_Width<<1;
-
- u422 = DNew unsigned char[Coded_Picture_Width * Coded_Picture_Height / 2];
- v422 = DNew unsigned char[Coded_Picture_Width * Coded_Picture_Height / 2];
- u444 = DNew unsigned char[Coded_Picture_Width * Coded_Picture_Height];
- v444 = DNew unsigned char[Coded_Picture_Width * Coded_Picture_Height];
- dstFrame = DNew unsigned char[Clip_Width * Clip_Height * 4]; // max value (super set)
-
- if(1 != sscanf(myfgets(buffer, sizeof(buffer), out->VF_File), "Field_Operation=%d\n", &FO_Flag))
- return 0;
- if(1 != sscanf(myfgets(buffer, sizeof(buffer), out->VF_File), "Frame_Rate=%d\n", &(out->VF_FrameRate)))
- return 0;
- if(4 != sscanf(myfgets(buffer, sizeof(buffer), out->VF_File), "Location=%d,%X,%d,%X\n", &i, &j, &i, &j))
- return 0;
-
- ntsc = film = top = bottom = gop = mapping = repeat_on = repeat_off = repeat_init = 0;
-
- while (1 == fscanf(out->VF_File, "%d", &type) && type<9)
- {
- if (type==7) // I frame
- {
- GOPList[gop] = reinterpret_cast<GOPLIST*>(calloc(1, sizeof(GOPLIST)));
- GOPList[gop]->number = film;
- if(2 != fscanf(out->VF_File, "%d %X", &(GOPList[gop]->file), &j))
- break;
-
- GOPList[gop]->position = (__int64)j*BUFFER_SIZE;
- gop ++;
-
- if(1 != fscanf(out->VF_File, "%d", &j))
- break;
-
- tff = j>>1;
- rff = j & 1;
- }
- else // P, B frame
- {
- tff = type>>1;
- rff = type & 1;
- }
-
- if (!film)
- {
- if (tff)
- Field_Order = 1;
- else
- Field_Order = 0;
- }
-
- if (FO_Flag==FO_FILM)
- {
- if (rff)
- repeat_on++;
- else
- repeat_off++;
-
- if (repeat_init)
- {
- if (repeat_off-repeat_on == 5)
- {
- repeat_on = repeat_off = 0;
- }
- else
- {
- FrameList[mapping] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
- FrameList[mapping]->top = FrameList[mapping]->bottom = film;
- mapping ++;
- }
-
- if (repeat_on-repeat_off == 5)
- {
- repeat_on = repeat_off = 0;
- FrameList[mapping] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
- FrameList[mapping]->top = FrameList[mapping]->bottom = film;
- mapping ++;
- }
- }
- else
- {
- if (repeat_off-repeat_on == 3)
- {
- repeat_on = repeat_off = 0;
- repeat_init = 1;
- }
- else
- {
- FrameList[mapping] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
- FrameList[mapping]->top = FrameList[mapping]->bottom = film;
- mapping ++;
- }
-
- if (repeat_on-repeat_off == 3)
- {
- repeat_on = repeat_off = 0;
- repeat_init = 1;
-
- FrameList[mapping] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
- FrameList[mapping]->top = FrameList[mapping]->bottom = film;
- mapping ++;
- }
- }
- }
- else
- {
- if (top)
- {
- FrameList[ntsc]->bottom = film;
- ntsc ++;
- FrameList[ntsc] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
- FrameList[ntsc]->top = film;
- }
- else if (bottom)
- {
- FrameList[ntsc]->top = film;
- ntsc ++;
- FrameList[ntsc] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
- FrameList[ntsc]->bottom = film;
- }
- else
- {
- FrameList[ntsc] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
- FrameList[ntsc]->top = film;
- FrameList[ntsc]->bottom = film;
- ntsc ++;
- }
-
- if (rff)
- {
- if (!top && !bottom)
- FrameList[ntsc] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
-
- if (tff)
- {
- FrameList[ntsc]->top = film;
- top = 1;
- }
- else
- {
- FrameList[ntsc]->bottom = film;
- bottom = 1;
- }
-
- if (top && bottom)
- {
- top = bottom = 0;
- ntsc ++;
- }
- }
- }
-
- film ++;
- }
-
- out->VF_FrameBound = film;
- film -= 2;
-
- if (FO_Flag==FO_FILM)
- {
- while (FrameList[mapping-1]->top >= film)
- mapping --;
-
- out->VF_FrameLimit = mapping;
- }
- else
- {
- if (FO_Flag==FO_SWAP)
- {
- Field_Order = !Field_Order;
-
- if (Field_Order)
- for (i=0; i<ntsc-1; i++)
- FrameList[i]->bottom = FrameList[i+1]->bottom;
- else
- for (i=0; i<ntsc-1; i++)
- FrameList[i]->top = FrameList[i+1]->top;
- }
-
- while ((FrameList[ntsc-1]->top >= film) || (FrameList[ntsc-1]->bottom >= film))
- ntsc --;
-
- out->VF_FrameLimit = ntsc;
-
- for (i=0; i<out->VF_FrameLimit-1; i++)
- if (FrameList[i]->top==FrameList[i+1]->top || FrameList[i]->top==FrameList[i+1]->bottom ||
- FrameList[i]->bottom==FrameList[i+1]->top || FrameList[i]->bottom==FrameList[i+1]->bottom)
- {
- FrameList[i]->forward = 1;
- FrameList[i+1]->backward = 1;
- }
- }
-
- Full_Frame = 1;
- for (i=0; i<out->VF_FrameLimit; i++)
- if (FrameList[i]->top!=FrameList[i]->bottom)
- {
- Full_Frame = 0;
- break;
- }
-
- out->VF_GOPNow = out->VF_GOPLimit = gop;
- out->VF_OldFrame = out->VF_FrameLimit;
- out->VF_FrameSize = Clip_Width * Clip_Height * 3;
-
- return 1;
+ m_dstFormat = dstFormat;
+ char ID[19], PASS[19] = "DVD2AVIProjectFile";
+ DWORD i, j, size, code, type, tff, rff, film, ntsc, gop, top, bottom, mapping;
+ int repeat_on, repeat_off, repeat_init;
+ int Clip_Top, Clip_Bottom, Clip_Left, Clip_Right, Squeeze_Width, Squeeze_Height;
+
+ HKEY key;
+ DWORD value = REG_SZ;
+ DWORD length = 256;
+ char *ext, buffer[256];
+
+ CMPEG2Dec* out = this;
+
+ out->VF_File = _tfopen(path, _T("r"));
+ if(out->VF_File == NULL)
+ return 0;
+ if(fgets(ID, 19, out->VF_File) == NULL)
+ return 0;
+ if(strcmp(ID, PASS))
+ return 0;
+
+ // load DLL
+ if(RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\VFPlugin", 0, KEY_ALL_ACCESS, &key) == ERROR_SUCCESS)
+ {
+ RegQueryValueExA(key, "DVD2AVI", NULL, &value, (unsigned char*)buffer, &length);
+
+ ext = strrchr(buffer, '\\');
+ sprintf(buffer + (int)(ext - buffer) + 1, "OpenDVD.dll");
+ RegCloseKey(key);
+ }
+
+ if((hLibrary = LoadLibraryA(buffer)) != NULL)
+ BufferOp = (PBufferOp) GetProcAddress(hLibrary, "BufferOp");
+
+ for(i = 0; i < MAX_FILE_NUMBER; i++)
+ Infilename[i] = DNew char[_MAX_PATH];
+
+ if(1 != fscanf(out->VF_File, "%d", &File_Limit))
+ return 0;
+
+ i = File_Limit;
+ while(i)
+ {
+ if(1 != fscanf(out->VF_File, "%d ", &j))
+ return 0;
+ fgets(Infilename[File_Limit-i], j + 1, out->VF_File);
+ if((Infile[File_Limit-i] = _open(Infilename[File_Limit-i], _O_RDONLY | _O_BINARY)) == -1)
+ return 0;
+ i--;
+ }
+
+ if(3 != sscanf(myfgets(buffer, sizeof(buffer), out->VF_File), "\nStream_Type=%d,%X,%X\n", &SystemStream_Flag, &lfsr0, &lfsr1))
+ return 0;
+ if(lfsr0 || lfsr1)
+ KeyOp_Flag = 1;
+ else
+ KeyOp_Flag = 0;
+
+ if(1 != sscanf(myfgets(buffer, sizeof(buffer), out->VF_File), "iDCT_Algorithm=%d\n", &IDCT_Flag))
+ return 0;
+
+ switch(IDCT_Flag)
+ {
+ case IDCT_SSEMMX:
+ if(!cpu.ssemmx)
+ IDCT_Flag = IDCT_MMX;
+ break;
+
+ case IDCT_FPU:
+ Initialize_FPU_IDCT();
+ break;
+
+ case IDCT_REF:
+ Initialize_REF_IDCT();
+ break;
+ }
+
+ File_Flag = 0;
+ _lseeki64(Infile[0], 0, SEEK_SET);
+ Initialize_Buffer();
+
+ do
+ {
+ next_start_code();
+ code = Get_Bits(32);
+ }
+ while(code != SEQUENCE_HEADER_CODE);
+
+ sequence_header();
+
+ mb_width = (horizontal_size + 15) / 16;
+ mb_height = progressive_sequence ? (vertical_size + 15) / 16 : 2 * ((vertical_size + 31) / 32);
+
+ Coded_Picture_Width = 16 * mb_width;
+ Coded_Picture_Height = 16 * mb_height;
+
+ Chroma_Width = (chroma_format == CHROMA444) ? Coded_Picture_Width : Coded_Picture_Width >> 1;
+ Chroma_Height = (chroma_format != CHROMA420) ? Coded_Picture_Height : Coded_Picture_Height >> 1;
+
+ block_count = ChromaFormat[chroma_format];
+
+ for(i = 0; i < 8; i++)
+ {
+ p_block[i] = (short *)DNew BYTE[sizeof(short)*64 + 64];
+ block[i] = (short *)((long)p_block[i] + 64 - (long)p_block[i] % 64);
+ }
+
+ p_fTempArray = (void *)DNew BYTE[sizeof(float)*128 + 64];
+ fTempArray = (void *)((long)p_fTempArray + 64 - (long)p_fTempArray % 64);
+
+ for(i = 0; i < 3; i++)
+ {
+ if(i == 0)
+ size = Coded_Picture_Width * Coded_Picture_Height;
+ else
+ size = Chroma_Width * Chroma_Height;
+
+ backward_reference_frame[i] = DNew unsigned char[size];
+ forward_reference_frame[i] = DNew unsigned char[size];
+ auxframe[i] = DNew unsigned char[size];
+ }
+
+ if(1 != sscanf(myfgets(buffer, sizeof(buffer), out->VF_File), "YUVRGB_Scale=%d\n", &i))
+ return 0;
+
+ if(i)
+ {
+ RGB_Scale = 0x1000254310002543;
+ RGB_Offset = 0x0010001000100010;
+ RGB_CBU = 0x0000408D0000408D;
+ RGB_CGX = 0xF377E5FCF377E5FC;
+ RGB_CRV = 0x0000331300003313;
+ }
+ else
+ {
+ RGB_Scale = 0x1000200010002000;
+ RGB_Offset = 0x0000000000000000;
+ RGB_CBU = 0x000038B4000038B4;
+ RGB_CGX = 0xF4FDE926F4FDE926;
+ RGB_CRV = 0x00002CDD00002CDD;
+ }
+
+ char* tmp = myfgets(buffer, sizeof(buffer), out->VF_File);
+ if(2 != sscanf(tmp, "Luminance=%d,%d\n", &i, &j))
+ {
+ if(2 != sscanf(tmp, "Luminance_Filter=%d,%d\n", &i, &j))
+ return 0;
+ i = 128;
+ j = 0;
+ }
+
+ if(i == 128 && j == 0)
+ Luminance_Flag = 0;
+ else
+ {
+ Luminance_Flag = 1;
+ LumGainMask = ((__int64)i << 48) + ((__int64)i << 32) + ((__int64)i << 16) + (__int64)i;
+ LumOffsetMask = ((__int64)j << 48) + ((__int64)j << 32) + ((__int64)j << 16) + (__int64)j;
+
+ lum = DNew unsigned char[Coded_Picture_Width * Coded_Picture_Height];
+ }
+
+ if(6 != sscanf(myfgets(buffer, sizeof(buffer), out->VF_File), "Picture_Size=%d,%d,%d,%d,%d,%d\n",
+ &Clip_Top, &Clip_Bottom, &Clip_Left, &Clip_Right, &Squeeze_Width, &Squeeze_Height))
+ return 0;
+
+ Resize_Flag = 0;
+ Resize_Width = Clip_Width = Coded_Picture_Width;
+ Resize_Height = Clip_Height = Coded_Picture_Height;
+ CLIP_AREA = HALF_CLIP_AREA = CLIP_STEP = 0;
+
+ if(Clip_Top || Clip_Bottom || Clip_Left || Clip_Right)
+ {
+ Clip_Width -= Clip_Left + Clip_Right;
+ Clip_Height -= Clip_Top + Clip_Bottom;
+ Resize_Width = Clip_Width;
+ Resize_Height = Clip_Height;
+
+ CLIP_AREA = Coded_Picture_Width * Clip_Top;
+ HALF_CLIP_AREA = (Coded_Picture_Width >> 1) * Clip_Top;
+ CLIP_STEP = Coded_Picture_Width * Clip_Top + Clip_Left;
+ }
+
+ if(Squeeze_Width || Squeeze_Height)
+ {
+ Resize_Flag = 1;
+ Resize_Width -= Squeeze_Width;
+ Resize_Height -= Squeeze_Height;
+ }
+
+ DSTBYTES = Clip_Width * (dstRGB24() ? 3 : 2);
+ DSTBYTES2 = DSTBYTES * 2;
+ LUM_AREA = Coded_Picture_Width * Clip_Height;
+ PROGRESSIVE_HEIGHT = (Coded_Picture_Height >> 1) - 2;
+ INTERLACED_HEIGHT = (Coded_Picture_Height >> 2) - 2;
+ HALF_WIDTH = Coded_Picture_Width >> 1;
+ HALF_WIDTH_D8 = (Coded_Picture_Width >> 1) - 8;
+ DOUBLE_WIDTH = Coded_Picture_Width << 1;
+
+ u422 = DNew unsigned char[Coded_Picture_Width * Coded_Picture_Height / 2];
+ v422 = DNew unsigned char[Coded_Picture_Width * Coded_Picture_Height / 2];
+ u444 = DNew unsigned char[Coded_Picture_Width * Coded_Picture_Height];
+ v444 = DNew unsigned char[Coded_Picture_Width * Coded_Picture_Height];
+ dstFrame = DNew unsigned char[Clip_Width * Clip_Height * 4]; // max value (super set)
+
+ if(1 != sscanf(myfgets(buffer, sizeof(buffer), out->VF_File), "Field_Operation=%d\n", &FO_Flag))
+ return 0;
+ if(1 != sscanf(myfgets(buffer, sizeof(buffer), out->VF_File), "Frame_Rate=%d\n", &(out->VF_FrameRate)))
+ return 0;
+ if(4 != sscanf(myfgets(buffer, sizeof(buffer), out->VF_File), "Location=%d,%X,%d,%X\n", &i, &j, &i, &j))
+ return 0;
+
+ ntsc = film = top = bottom = gop = mapping = repeat_on = repeat_off = repeat_init = 0;
+
+ while(1 == fscanf(out->VF_File, "%d", &type) && type < 9)
+ {
+ if(type == 7) // I frame
+ {
+ GOPList[gop] = reinterpret_cast<GOPLIST*>(calloc(1, sizeof(GOPLIST)));
+ GOPList[gop]->number = film;
+ if(2 != fscanf(out->VF_File, "%d %X", &(GOPList[gop]->file), &j))
+ break;
+
+ GOPList[gop]->position = (__int64)j * BUFFER_SIZE;
+ gop ++;
+
+ if(1 != fscanf(out->VF_File, "%d", &j))
+ break;
+
+ tff = j >> 1;
+ rff = j & 1;
+ }
+ else // P, B frame
+ {
+ tff = type >> 1;
+ rff = type & 1;
+ }
+
+ if(!film)
+ {
+ if(tff)
+ Field_Order = 1;
+ else
+ Field_Order = 0;
+ }
+
+ if(FO_Flag == FO_FILM)
+ {
+ if(rff)
+ repeat_on++;
+ else
+ repeat_off++;
+
+ if(repeat_init)
+ {
+ if(repeat_off - repeat_on == 5)
+ {
+ repeat_on = repeat_off = 0;
+ }
+ else
+ {
+ FrameList[mapping] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
+ FrameList[mapping]->top = FrameList[mapping]->bottom = film;
+ mapping ++;
+ }
+
+ if(repeat_on - repeat_off == 5)
+ {
+ repeat_on = repeat_off = 0;
+ FrameList[mapping] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
+ FrameList[mapping]->top = FrameList[mapping]->bottom = film;
+ mapping ++;
+ }
+ }
+ else
+ {
+ if(repeat_off - repeat_on == 3)
+ {
+ repeat_on = repeat_off = 0;
+ repeat_init = 1;
+ }
+ else
+ {
+ FrameList[mapping] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
+ FrameList[mapping]->top = FrameList[mapping]->bottom = film;
+ mapping ++;
+ }
+
+ if(repeat_on - repeat_off == 3)
+ {
+ repeat_on = repeat_off = 0;
+ repeat_init = 1;
+
+ FrameList[mapping] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
+ FrameList[mapping]->top = FrameList[mapping]->bottom = film;
+ mapping ++;
+ }
+ }
+ }
+ else
+ {
+ if(top)
+ {
+ FrameList[ntsc]->bottom = film;
+ ntsc ++;
+ FrameList[ntsc] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
+ FrameList[ntsc]->top = film;
+ }
+ else if(bottom)
+ {
+ FrameList[ntsc]->top = film;
+ ntsc ++;
+ FrameList[ntsc] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
+ FrameList[ntsc]->bottom = film;
+ }
+ else
+ {
+ FrameList[ntsc] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
+ FrameList[ntsc]->top = film;
+ FrameList[ntsc]->bottom = film;
+ ntsc ++;
+ }
+
+ if(rff)
+ {
+ if(!top && !bottom)
+ FrameList[ntsc] = reinterpret_cast<FRAMELIST*>(calloc(1, sizeof(FRAMELIST)));
+
+ if(tff)
+ {
+ FrameList[ntsc]->top = film;
+ top = 1;
+ }
+ else
+ {
+ FrameList[ntsc]->bottom = film;
+ bottom = 1;
+ }
+
+ if(top && bottom)
+ {
+ top = bottom = 0;
+ ntsc ++;
+ }
+ }
+ }
+
+ film ++;
+ }
+
+ out->VF_FrameBound = film;
+ film -= 2;
+
+ if(FO_Flag == FO_FILM)
+ {
+ while(FrameList[mapping-1]->top >= film)
+ mapping --;
+
+ out->VF_FrameLimit = mapping;
+ }
+ else
+ {
+ if(FO_Flag == FO_SWAP)
+ {
+ Field_Order = !Field_Order;
+
+ if(Field_Order)
+ for(i = 0; i < ntsc - 1; i++)
+ FrameList[i]->bottom = FrameList[i+1]->bottom;
+ else
+ for(i = 0; i < ntsc - 1; i++)
+ FrameList[i]->top = FrameList[i+1]->top;
+ }
+
+ while((FrameList[ntsc-1]->top >= film) || (FrameList[ntsc-1]->bottom >= film))
+ ntsc --;
+
+ out->VF_FrameLimit = ntsc;
+
+ for(i = 0; i < out->VF_FrameLimit - 1; i++)
+ if(FrameList[i]->top == FrameList[i+1]->top || FrameList[i]->top == FrameList[i+1]->bottom ||
+ FrameList[i]->bottom == FrameList[i+1]->top || FrameList[i]->bottom == FrameList[i+1]->bottom)
+ {
+ FrameList[i]->forward = 1;
+ FrameList[i+1]->backward = 1;
+ }
+ }
+
+ Full_Frame = 1;
+ for(i = 0; i < out->VF_FrameLimit; i++)
+ if(FrameList[i]->top != FrameList[i]->bottom)
+ {
+ Full_Frame = 0;
+ break;
+ }
+
+ out->VF_GOPNow = out->VF_GOPLimit = gop;
+ out->VF_OldFrame = out->VF_FrameLimit;
+ out->VF_FrameSize = Clip_Width * Clip_Height * 3;
+
+ return 1;
}
void CMPEG2Dec::Decode(unsigned char *dst, DWORD frame, int pitch)
{
- DWORD i, now, size, origin, ref, fo;
- int remain;
-
- CMPEG2Dec* in = this;
-
- if (FO_Flag==FO_FILM)
- {
- fo = 0;
- frame = FrameList[frame]->top;
- }
-
- origin = frame;
-
- if (FO_Flag!=FO_FILM)
- {
- if (FrameList[frame]->top == FrameList[frame]->bottom)
- {
- fo = 0;
- frame = FrameList[frame]->top;
- }
- else if (FrameList[frame]->top < FrameList[frame]->bottom)
- {
- fo = 1;
- frame = FrameList[frame]->top;
- }
- else
- {
- fo = 2;
- frame = FrameList[frame]->bottom;
- }
- }
-
- ref = frame;
-
- if (frame >= GOPList[in->VF_GOPLimit-1]->number)
- {
- now = in->VF_GOPLimit-1;
- ref -= GOPList[in->VF_GOPLimit-1]->number;
- size = in->VF_FrameBound - GOPList[in->VF_GOPLimit-1]->number + 1;
- }
- else
- for (now = 0; now < (in->VF_GOPLimit-1); now++)
- {
- if (frame>=GOPList[now]->number && frame<GOPList[now+1]->number)
- {
- ref -= GOPList[now]->number;
- size = GOPList[now+1]->number - GOPList[now]->number + 1;
- break;
- }
- }
-
- if (fo)
- ref ++;
-
- if (now != in->VF_GOPNow)
- {
- if ((in->VF_OldFrame + 1)==origin)
- {
- if (Full_Frame)
- {
- Get_Hdr();
- Decode_Picture(1, dst, pitch);
-
- if (picture_structure!=FRAME_PICTURE)
- {
- Get_Hdr();
- Decode_Picture(1, dst, pitch);
- }
- }
- else
- switch (fo)
- {
- case 0:
- if (!FrameList[origin]->backward)
- {
- Get_Hdr();
- Decode_Picture(1, dst, pitch);
-
- if (picture_structure!=FRAME_PICTURE)
- {
- Get_Hdr();
- Decode_Picture(1, dst, pitch);
- }
-
- if (FrameList[origin]->forward)
- {
- if (Field_Order)
- Copyodd(dst, dstFrame, pitch, 1);
- else
- Copyeven(dst, dstFrame, pitch, 1);
- }
- }
- else
- {
- Copyodd(dstFrame, dst, pitch, 0);
- Copyeven(dstFrame, dst, pitch, 0);
- }
- break;
-
- case 1:
- Copyodd(dstFrame, dst, pitch, 0);
-
- Get_Hdr();
- Decode_Picture(1, dstFrame, DSTBYTES);
-
- if (picture_structure!=FRAME_PICTURE)
- {
- Get_Hdr();
- Decode_Picture(1, dstFrame, DSTBYTES);
- }
-
- Copyeven(dstFrame, dst, pitch, 0);
- break;
-
- case 2:
- Copyeven(dstFrame, dst, pitch, 0);
-
- Get_Hdr();
- Decode_Picture(1, dstFrame, DSTBYTES);
-
- if (picture_structure!=FRAME_PICTURE)
- {
- Get_Hdr();
- Decode_Picture(1, dstFrame, DSTBYTES);
- }
-
- Copyodd(dstFrame, dst, pitch, 0);
- break;
- }
-
- if (in->VF_GOPSize)
- {
- for (i=0; i < in->VF_GOPSize; i++)
- free(GOPBuffer[i]);
-
- in->VF_GOPSize = 0;
- }
-
- in->VF_GOPNow = in->VF_GOPLimit;
- in->VF_OldFrame = origin;
- return;
- }
-
- remain = ref;
- in->VF_OldRef = ref;
- in->VF_GOPNow = now;
- Second_Field = 0;
-
- if (size < in->VF_GOPSize)
- for (i=0; i < (in->VF_GOPSize - size); i++)
- free(GOPBuffer[size+i]);
- else if (size > in->VF_GOPSize)
- for (i=0; i < (size - in->VF_GOPSize); i++)
- GOPBuffer[in->VF_GOPSize+i] = reinterpret_cast<unsigned char*>(malloc(in->VF_FrameSize));
-
- in->VF_GOPSize = size;
-
- File_Flag = GOPList[now]->file;
- _lseeki64(Infile[GOPList[now]->file], GOPList[now]->position, SEEK_SET);
- Initialize_Buffer();
-
- while (Get_Hdr() && picture_coding_type!=I_TYPE);
-
- Decode_Picture(0, dst, pitch);
-
- while (Get_Hdr() && picture_coding_type==B_TYPE);
-
- if (picture_structure!=FRAME_PICTURE)
- {
- Decode_Picture(0, dst, pitch);
- Get_Hdr();
- }
-
- Decode_Picture(1, dst, pitch);
-
- if (picture_structure!=FRAME_PICTURE)
- {
- Get_Hdr();
- Decode_Picture(1, dst, pitch);
- }
-
- Copyodd(dst, GOPBuffer[0], pitch, 1);
- Copyeven(dst, GOPBuffer[0], pitch, 1);
-
- while (remain && Get_Hdr())
- {
- Decode_Picture(1, dst, pitch);
-
- if (picture_structure!=FRAME_PICTURE)
- {
- Get_Hdr();
- Decode_Picture(1, dst, pitch);
- }
-
- Copyodd(dst, GOPBuffer[ref - remain + 1], pitch, 1);
- Copyeven(dst, GOPBuffer[ref - remain + 1], pitch, 1);
-
- remain--;
- }
-
- if (!Full_Frame && ref>=(size-2))
- {
- Copyodd(dst, dstFrame, pitch, 1);
- Copyeven(dst, dstFrame, pitch, 1);
- }
- }
- else
- {
- remain = ref - in->VF_OldRef;
-
- if (remain > 0)
- {
- in->VF_OldRef = ref;
-
- while (remain && Get_Hdr())
- {
- Decode_Picture(1, dst, pitch);
-
- if (picture_structure!=FRAME_PICTURE)
- {
- Get_Hdr();
- Decode_Picture(1, dst, pitch);
- }
-
- Copyodd(dst, GOPBuffer[ref - remain + 1], pitch, 1);
- Copyeven(dst, GOPBuffer[ref - remain + 1], pitch, 1);
-
- remain--;
- }
-
- if (!Full_Frame && ref>=(size-2))
- {
- Copyodd(dst, dstFrame, pitch, 1);
- Copyeven(dst, dstFrame, pitch, 1);
- }
- }
- }
-
- switch (fo)
- {
- case 0:
- Copyodd(GOPBuffer[ref], dst, pitch, 0);
- Copyeven(GOPBuffer[ref], dst, pitch, 0);
- break;
-
- case 1:
- Copyodd(GOPBuffer[ref-1], dst, pitch, 0);
- Copyeven(GOPBuffer[ref], dst, pitch, 0);
- break;
-
- case 2:
- Copyodd(GOPBuffer[ref], dst, pitch, 0);
- Copyeven(GOPBuffer[ref-1], dst, pitch, 0);
- break;
- }
-
- in->VF_OldFrame = origin;
+ DWORD i, now, size, origin, ref, fo;
+ int remain;
+
+ CMPEG2Dec* in = this;
+
+ if(FO_Flag == FO_FILM)
+ {
+ fo = 0;
+ frame = FrameList[frame]->top;
+ }
+
+ origin = frame;
+
+ if(FO_Flag != FO_FILM)
+ {
+ if(FrameList[frame]->top == FrameList[frame]->bottom)
+ {
+ fo = 0;
+ frame = FrameList[frame]->top;
+ }
+ else if(FrameList[frame]->top < FrameList[frame]->bottom)
+ {
+ fo = 1;
+ frame = FrameList[frame]->top;
+ }
+ else
+ {
+ fo = 2;
+ frame = FrameList[frame]->bottom;
+ }
+ }
+
+ ref = frame;
+
+ if(frame >= GOPList[in->VF_GOPLimit-1]->number)
+ {
+ now = in->VF_GOPLimit - 1;
+ ref -= GOPList[in->VF_GOPLimit-1]->number;
+ size = in->VF_FrameBound - GOPList[in->VF_GOPLimit-1]->number + 1;
+ }
+ else
+ for(now = 0; now < (in->VF_GOPLimit - 1); now++)
+ {
+ if(frame >= GOPList[now]->number && frame < GOPList[now+1]->number)
+ {
+ ref -= GOPList[now]->number;
+ size = GOPList[now+1]->number - GOPList[now]->number + 1;
+ break;
+ }
+ }
+
+ if(fo)
+ ref ++;
+
+ if(now != in->VF_GOPNow)
+ {
+ if((in->VF_OldFrame + 1) == origin)
+ {
+ if(Full_Frame)
+ {
+ Get_Hdr();
+ Decode_Picture(1, dst, pitch);
+
+ if(picture_structure != FRAME_PICTURE)
+ {
+ Get_Hdr();
+ Decode_Picture(1, dst, pitch);
+ }
+ }
+ else
+ switch(fo)
+ {
+ case 0:
+ if(!FrameList[origin]->backward)
+ {
+ Get_Hdr();
+ Decode_Picture(1, dst, pitch);
+
+ if(picture_structure != FRAME_PICTURE)
+ {
+ Get_Hdr();
+ Decode_Picture(1, dst, pitch);
+ }
+
+ if(FrameList[origin]->forward)
+ {
+ if(Field_Order)
+ Copyodd(dst, dstFrame, pitch, 1);
+ else
+ Copyeven(dst, dstFrame, pitch, 1);
+ }
+ }
+ else
+ {
+ Copyodd(dstFrame, dst, pitch, 0);
+ Copyeven(dstFrame, dst, pitch, 0);
+ }
+ break;
+
+ case 1:
+ Copyodd(dstFrame, dst, pitch, 0);
+
+ Get_Hdr();
+ Decode_Picture(1, dstFrame, DSTBYTES);
+
+ if(picture_structure != FRAME_PICTURE)
+ {
+ Get_Hdr();
+ Decode_Picture(1, dstFrame, DSTBYTES);
+ }
+
+ Copyeven(dstFrame, dst, pitch, 0);
+ break;
+
+ case 2:
+ Copyeven(dstFrame, dst, pitch, 0);
+
+ Get_Hdr();
+ Decode_Picture(1, dstFrame, DSTBYTES);
+
+ if(picture_structure != FRAME_PICTURE)
+ {
+ Get_Hdr();
+ Decode_Picture(1, dstFrame, DSTBYTES);
+ }
+
+ Copyodd(dstFrame, dst, pitch, 0);
+ break;
+ }
+
+ if(in->VF_GOPSize)
+ {
+ for(i = 0; i < in->VF_GOPSize; i++)
+ free(GOPBuffer[i]);
+
+ in->VF_GOPSize = 0;
+ }
+
+ in->VF_GOPNow = in->VF_GOPLimit;
+ in->VF_OldFrame = origin;
+ return;
+ }
+
+ remain = ref;
+ in->VF_OldRef = ref;
+ in->VF_GOPNow = now;
+ Second_Field = 0;
+
+ if(size < in->VF_GOPSize)
+ for(i = 0; i < (in->VF_GOPSize - size); i++)
+ free(GOPBuffer[size+i]);
+ else if(size > in->VF_GOPSize)
+ for(i = 0; i < (size - in->VF_GOPSize); i++)
+ GOPBuffer[in->VF_GOPSize+i] = reinterpret_cast<unsigned char*>(malloc(in->VF_FrameSize));
+
+ in->VF_GOPSize = size;
+
+ File_Flag = GOPList[now]->file;
+ _lseeki64(Infile[GOPList[now]->file], GOPList[now]->position, SEEK_SET);
+ Initialize_Buffer();
+
+ while(Get_Hdr() && picture_coding_type != I_TYPE);
+
+ Decode_Picture(0, dst, pitch);
+
+ while(Get_Hdr() && picture_coding_type == B_TYPE);
+
+ if(picture_structure != FRAME_PICTURE)
+ {
+ Decode_Picture(0, dst, pitch);
+ Get_Hdr();
+ }
+
+ Decode_Picture(1, dst, pitch);
+
+ if(picture_structure != FRAME_PICTURE)
+ {
+ Get_Hdr();
+ Decode_Picture(1, dst, pitch);
+ }
+
+ Copyodd(dst, GOPBuffer[0], pitch, 1);
+ Copyeven(dst, GOPBuffer[0], pitch, 1);
+
+ while(remain && Get_Hdr())
+ {
+ Decode_Picture(1, dst, pitch);
+
+ if(picture_structure != FRAME_PICTURE)
+ {
+ Get_Hdr();
+ Decode_Picture(1, dst, pitch);
+ }
+
+ Copyodd(dst, GOPBuffer[ref - remain + 1], pitch, 1);
+ Copyeven(dst, GOPBuffer[ref - remain + 1], pitch, 1);
+
+ remain--;
+ }
+
+ if(!Full_Frame && ref >= (size - 2))
+ {
+ Copyodd(dst, dstFrame, pitch, 1);
+ Copyeven(dst, dstFrame, pitch, 1);
+ }
+ }
+ else
+ {
+ remain = ref - in->VF_OldRef;
+
+ if(remain > 0)
+ {
+ in->VF_OldRef = ref;
+
+ while(remain && Get_Hdr())
+ {
+ Decode_Picture(1, dst, pitch);
+
+ if(picture_structure != FRAME_PICTURE)
+ {
+ Get_Hdr();
+ Decode_Picture(1, dst, pitch);
+ }
+
+ Copyodd(dst, GOPBuffer[ref - remain + 1], pitch, 1);
+ Copyeven(dst, GOPBuffer[ref - remain + 1], pitch, 1);
+
+ remain--;
+ }
+
+ if(!Full_Frame && ref >= (size - 2))
+ {
+ Copyodd(dst, dstFrame, pitch, 1);
+ Copyeven(dst, dstFrame, pitch, 1);
+ }
+ }
+ }
+
+ switch(fo)
+ {
+ case 0:
+ Copyodd(GOPBuffer[ref], dst, pitch, 0);
+ Copyeven(GOPBuffer[ref], dst, pitch, 0);
+ break;
+
+ case 1:
+ Copyodd(GOPBuffer[ref-1], dst, pitch, 0);
+ Copyeven(GOPBuffer[ref], dst, pitch, 0);
+ break;
+
+ case 2:
+ Copyodd(GOPBuffer[ref], dst, pitch, 0);
+ Copyeven(GOPBuffer[ref-1], dst, pitch, 0);
+ break;
+ }
+
+ in->VF_OldFrame = origin;
}
void CMPEG2Dec::Close()
{
- int i;
+ int i;
- for(i = 0; i < VF_GOPLimit; i++) free(GOPList[i]);
- for(i = 0; i < VF_FrameLimit; i++) free(FrameList[i]);
+ for(i = 0; i < VF_GOPLimit; i++) free(GOPList[i]);
+ for(i = 0; i < VF_FrameLimit; i++) free(FrameList[i]);
- if (VF_File != NULL)
- fclose(VF_File);
+ if(VF_File != NULL)
+ fclose(VF_File);
- while (VF_GOPSize)
- {
- VF_GOPSize--;
- free(GOPBuffer[VF_GOPSize]);
- }
+ while(VF_GOPSize)
+ {
+ VF_GOPSize--;
+ free(GOPBuffer[VF_GOPSize]);
+ }
- while (File_Limit)
- {
- File_Limit--;
- _close(Infile[File_Limit]);
- }
+ while(File_Limit)
+ {
+ File_Limit--;
+ _close(Infile[File_Limit]);
+ }
- for (i=0; i<MAX_FILE_NUMBER; i++)
- delete [] Infilename[i];
+ for(i = 0; i < MAX_FILE_NUMBER; i++)
+ delete [] Infilename[i];
- for (i=0; i<3; i++)
- {
- delete [] backward_reference_frame[i];
- delete [] forward_reference_frame[i];
- delete [] auxframe[i];
- }
+ for(i = 0; i < 3; i++)
+ {
+ delete [] backward_reference_frame[i];
+ delete [] forward_reference_frame[i];
+ delete [] auxframe[i];
+ }
- delete [] u422;
- delete [] v422;
- delete [] u444;
- delete [] v444;
- delete [] dstFrame;
+ delete [] u422;
+ delete [] v422;
+ delete [] u444;
+ delete [] v444;
+ delete [] dstFrame;
- if(Luminance_Flag)
- delete [] lum;
+ if(Luminance_Flag)
+ delete [] lum;
- for (i=0; i<8; i++)
- delete [] p_block[i];
+ for(i = 0; i < 8; i++)
+ delete [] p_block[i];
- delete [] p_fTempArray;
+ delete [] p_fTempArray;
- if (hLibrary)
- FreeLibrary(hLibrary);
+ if(hLibrary)
+ FreeLibrary(hLibrary);
}
void CMPEG2Dec::Copyodd(unsigned char *src, unsigned char *dst, int pitch, int forward)
{
- int i;
- int PWIDTH = forward ? (pitch<<1) : DSTBYTES2;
- int QWIDTH = forward ? DSTBYTES2 : (pitch<<1);
-
- for (i=0; i<(Clip_Height>>1); i++)
- {
- memcpy (dst, src, DSTBYTES);
- src += PWIDTH;
- dst += QWIDTH;
- }
+ int i;
+ int PWIDTH = forward ? (pitch << 1) : DSTBYTES2;
+ int QWIDTH = forward ? DSTBYTES2 : (pitch << 1);
+
+ for(i = 0; i<(Clip_Height >> 1); i++)
+ {
+ memcpy(dst, src, DSTBYTES);
+ src += PWIDTH;
+ dst += QWIDTH;
+ }
}
void CMPEG2Dec::Copyeven(unsigned char *src, unsigned char *dst, int pitch, int forward)
{
- int i;
- int PWIDTH = forward ? (pitch<<1) : DSTBYTES2;
- int QWIDTH = forward ? DSTBYTES2 : (pitch<<1);
- src += forward ? pitch : DSTBYTES;
- dst += forward ? DSTBYTES : pitch;
-
- for (i=0; i<(Clip_Height>>1); i++)
- {
- memcpy (dst, src, DSTBYTES);
- src += PWIDTH;
- dst += QWIDTH;
- }
+ int i;
+ int PWIDTH = forward ? (pitch << 1) : DSTBYTES2;
+ int QWIDTH = forward ? DSTBYTES2 : (pitch << 1);
+ src += forward ? pitch : DSTBYTES;
+ dst += forward ? DSTBYTES : pitch;
+
+ for(i = 0; i<(Clip_Height >> 1); i++)
+ {
+ memcpy(dst, src, DSTBYTES);
+ src += PWIDTH;
+ dst += QWIDTH;
+ }
}
diff --git a/src/filters/source/D2VSource/MPEG2Dec.h b/src/filters/source/D2VSource/MPEG2Dec.h
index 34368208b..aea3f4f07 100644
--- a/src/filters/source/D2VSource/MPEG2Dec.h
+++ b/src/filters/source/D2VSource/MPEG2Dec.h
@@ -73,232 +73,244 @@
#define FO_SWAP 2
-typedef void (WINAPI *PBufferOp) (unsigned char*, int, int);
+typedef void (WINAPI *PBufferOp)(unsigned char*, int, int);
#define MAX_FRAME_NUMBER 1000000
#define MAX_GOP_SIZE 1024
-class CMPEG2Dec
+class CMPEG2Dec
{
protected:
- // getbit.cpp
- void Initialize_Buffer();
- void Fill_Buffer();
- void Next_Packet();
- void Flush_Buffer_All(unsigned int N);
- unsigned int Get_Bits_All(unsigned int N);
- void Next_File();
-
- unsigned int Show_Bits(unsigned int N);
- unsigned int Get_Bits(unsigned int N);
- void Flush_Buffer(unsigned int N);
- void Fill_Next();
- unsigned int Get_Byte();
- unsigned int Get_Short();
- void next_start_code();
-
- unsigned char Rdbfr[BUFFER_SIZE], *Rdptr, *Rdmax;
- unsigned int CurrentBfr, NextBfr, BitsLeft, Val, Read;
-
- // gethdr.cpp
- int Get_Hdr();
- void sequence_header();
- int slice_header();
+ // getbit.cpp
+ void Initialize_Buffer();
+ void Fill_Buffer();
+ void Next_Packet();
+ void Flush_Buffer_All(unsigned int N);
+ unsigned int Get_Bits_All(unsigned int N);
+ void Next_File();
+
+ unsigned int Show_Bits(unsigned int N);
+ unsigned int Get_Bits(unsigned int N);
+ void Flush_Buffer(unsigned int N);
+ void Fill_Next();
+ unsigned int Get_Byte();
+ unsigned int Get_Short();
+ void next_start_code();
+
+ unsigned char Rdbfr[BUFFER_SIZE], *Rdptr, *Rdmax;
+ unsigned int CurrentBfr, NextBfr, BitsLeft, Val, Read;
+
+ // gethdr.cpp
+ int Get_Hdr();
+ void sequence_header();
+ int slice_header();
private:
- void group_of_pictures_header();
- void picture_header();
- void sequence_extension();
- void sequence_display_extension();
- void quant_matrix_extension();
- void picture_display_extension();
- void picture_coding_extension();
- void copyright_extension();
- int extra_bit_information();
- void extension_and_user_data();
+ void group_of_pictures_header();
+ void picture_header();
+ void sequence_extension();
+ void sequence_display_extension();
+ void quant_matrix_extension();
+ void picture_display_extension();
+ void picture_coding_extension();
+ void copyright_extension();
+ int extra_bit_information();
+ void extension_and_user_data();
protected:
- // getpic.cpp
- void Decode_Picture(int ref, unsigned char *dst, int pitch);
+ // getpic.cpp
+ void Decode_Picture(int ref, unsigned char *dst, int pitch);
private:
- void Update_Picture_Buffers();
- void picture_data();
- int slice(int MBAmax);
- void macroblock_modes(int *pmacroblock_type, int *pmotion_type,
- int *pmotion_vector_count, int *pmv_format, int *pdmv, int *pmvscale, int *pdct_type);
- void Clear_Block(int count);
- void Add_Block(int count, int bx, int by, int dct_type, int addflag);
- void motion_compensation(int MBA, int macroblock_type, int motion_type,
- int PMV[2][2][2], int motion_vertical_field_select[2][2], int dmvector[2], int dct_type);
- void skipped_macroblock(int dc_dct_pred[3], int PMV[2][2][2],
- int *motion_type, int motion_vertical_field_select[2][2], int *macroblock_type);
- int start_of_slice(int *MBA, int *MBAinc, int dc_dct_pred[3], int PMV[2][2][2]);
- int decode_macroblock(int *macroblock_type, int *motion_type, int *dct_type,
- int PMV[2][2][2], int dc_dct_pred[3], int motion_vertical_field_select[2][2], int dmvector[2]);
- void Decode_MPEG2_Intra_Block(int comp, int dc_dct_pred[]);
- void Decode_MPEG2_Non_Intra_Block(int comp);
-
- int Get_macroblock_type();
- int Get_I_macroblock_type();
- int Get_P_macroblock_type();
- int Get_B_macroblock_type();
- int Get_D_macroblock_type();
- int Get_coded_block_pattern();
- int Get_macroblock_address_increment();
- int Get_Luma_DC_dct_diff();
- int Get_Chroma_DC_dct_diff();
-
- void form_predictions(int bx, int by, int macroblock_type, int motion_type,
- int PMV[2][2][2], int motion_vertical_field_select[2][2], int dmvector[2]);
- void form_prediction(unsigned char *src[], int sfield, unsigned char *dst[], int dfield,
- int lx, int lx2, int w, int h, int x, int y, int dx, int dy, int average_flag);
- void form_component_prediction(unsigned char *src, unsigned char *dst,
- int lx, int lx2, int w, int h, int x, int y, int dx, int dy, int average_flag);
-
- // motion.cpp
- void motion_vectors(int PMV[2][2][2], int dmvector[2], int motion_vertical_field_select[2][2],
- int s, int motion_vector_count, int mv_format,
- int h_r_size, int v_r_size, int dmv, int mvscale);
- void Dual_Prime_Arithmetic(int DMV[][2], int *dmvector, int mvx, int mvy);
+ void Update_Picture_Buffers();
+ void picture_data();
+ int slice(int MBAmax);
+ void macroblock_modes(int *pmacroblock_type, int *pmotion_type,
+ int *pmotion_vector_count, int *pmv_format, int *pdmv, int *pmvscale, int *pdct_type);
+ void Clear_Block(int count);
+ void Add_Block(int count, int bx, int by, int dct_type, int addflag);
+ void motion_compensation(int MBA, int macroblock_type, int motion_type,
+ int PMV[2][2][2], int motion_vertical_field_select[2][2], int dmvector[2], int dct_type);
+ void skipped_macroblock(int dc_dct_pred[3], int PMV[2][2][2],
+ int *motion_type, int motion_vertical_field_select[2][2], int *macroblock_type);
+ int start_of_slice(int *MBA, int *MBAinc, int dc_dct_pred[3], int PMV[2][2][2]);
+ int decode_macroblock(int *macroblock_type, int *motion_type, int *dct_type,
+ int PMV[2][2][2], int dc_dct_pred[3], int motion_vertical_field_select[2][2], int dmvector[2]);
+ void Decode_MPEG2_Intra_Block(int comp, int dc_dct_pred[]);
+ void Decode_MPEG2_Non_Intra_Block(int comp);
+
+ int Get_macroblock_type();
+ int Get_I_macroblock_type();
+ int Get_P_macroblock_type();
+ int Get_B_macroblock_type();
+ int Get_D_macroblock_type();
+ int Get_coded_block_pattern();
+ int Get_macroblock_address_increment();
+ int Get_Luma_DC_dct_diff();
+ int Get_Chroma_DC_dct_diff();
+
+ void form_predictions(int bx, int by, int macroblock_type, int motion_type,
+ int PMV[2][2][2], int motion_vertical_field_select[2][2], int dmvector[2]);
+ void form_prediction(unsigned char *src[], int sfield, unsigned char *dst[], int dfield,
+ int lx, int lx2, int w, int h, int x, int y, int dx, int dy, int average_flag);
+ void form_component_prediction(unsigned char *src, unsigned char *dst,
+ int lx, int lx2, int w, int h, int x, int y, int dx, int dy, int average_flag);
+
+ // motion.cpp
+ void motion_vectors(int PMV[2][2][2], int dmvector[2], int motion_vertical_field_select[2][2],
+ int s, int motion_vector_count, int mv_format,
+ int h_r_size, int v_r_size, int dmv, int mvscale);
+ void Dual_Prime_Arithmetic(int DMV[][2], int *dmvector, int mvx, int mvy);
private:
- void motion_vector(int *PMV, int *dmvector, int h_r_size, int v_r_size,
- int dmv, int mvscale, int full_pel_vector);
- void decode_motion_vector(int *pred, int r_size, int motion_code,
- int motion_residualesidual, int full_pel_vector);
- int Get_motion_code();
- int Get_dmvector();
+ void motion_vector(int *PMV, int *dmvector, int h_r_size, int v_r_size,
+ int dmv, int mvscale, int full_pel_vector);
+ void decode_motion_vector(int *pred, int r_size, int motion_code,
+ int motion_residualesidual, int full_pel_vector);
+ int Get_motion_code();
+ int Get_dmvector();
protected:
- // store.cpp
- void assembleFrame(unsigned char *src[], int pf, unsigned char *dst, int pitch);
+ // store.cpp
+ void assembleFrame(unsigned char *src[], int pf, unsigned char *dst, int pitch);
private:
- void Luminance_Filter(unsigned char *src, unsigned char *dst);
- void conv420to422(unsigned char *src, unsigned char *dst, int frame_type);
- void conv422to444(unsigned char *src, unsigned char *dst);
- void conv444toRGB24(unsigned char *py, unsigned char *pu, unsigned char *pv, unsigned char *dst, int pitch);
- void conv422toYUY2(unsigned char *py, unsigned char *pu, unsigned char *pv, unsigned char *dst, int pitch);
+ void Luminance_Filter(unsigned char *src, unsigned char *dst);
+ void conv420to422(unsigned char *src, unsigned char *dst, int frame_type);
+ void conv422to444(unsigned char *src, unsigned char *dst);
+ void conv444toRGB24(unsigned char *py, unsigned char *pu, unsigned char *pv, unsigned char *dst, int pitch);
+ void conv422toYUY2(unsigned char *py, unsigned char *pu, unsigned char *pv, unsigned char *dst, int pitch);
protected:
- // decoder operation control flags
- int Fault_Flag;
- int File_Flag;
- int File_Limit;
- int FO_Flag;
- int IDCT_Flag;
- int SystemStream_Flag;
-
- int Luminance_Flag;
- int Resize_Flag;
-
- int KeyOp_Flag;
- int lfsr0, lfsr1;
- PBufferOp BufferOp;
-
- int Infile[MAX_FILE_NUMBER];
- char *Infilename[MAX_FILE_NUMBER];
-
- int intra_quantizer_matrix[64];
- int non_intra_quantizer_matrix[64];
- int chroma_intra_quantizer_matrix[64];
- int chroma_non_intra_quantizer_matrix[64];
-
- int load_intra_quantizer_matrix;
- int load_non_intra_quantizer_matrix;
- int load_chroma_intra_quantizer_matrix;
- int load_chroma_non_intra_quantizer_matrix;
-
- int q_scale_type;
- int alternate_scan;
- int quantizer_scale;
-
- void *fTempArray, *p_fTempArray;
- short *block[8], *p_block[8];
- int pf_backward, pf_forward, pf_current;
-
- // global values
- unsigned char *backward_reference_frame[3], *forward_reference_frame[3];
- unsigned char *auxframe[3], *current_frame[3];
- unsigned char *u422, *v422, *u444, *v444, /* *rgb24,*/ *lum;
- unsigned char *dstFrame; // replaces rgb24
- __int64 RGB_Scale, RGB_Offset, RGB_CRV, RGB_CBU, RGB_CGX, LumOffsetMask, LumGainMask;
-
- int HALF_WIDTH, PROGRESSIVE_HEIGHT, INTERLACED_HEIGHT, DOUBLE_WIDTH;
- int /*TWIDTH, SWIDTH,*/ HALF_WIDTH_D8, LUM_AREA, CLIP_AREA, HALF_CLIP_AREA, CLIP_STEP;
- int DSTBYTES, DSTBYTES2; // these replace TWIDTH and SWIDTH
+ // decoder operation control flags
+ int Fault_Flag;
+ int File_Flag;
+ int File_Limit;
+ int FO_Flag;
+ int IDCT_Flag;
+ int SystemStream_Flag;
+
+ int Luminance_Flag;
+ int Resize_Flag;
+
+ int KeyOp_Flag;
+ int lfsr0, lfsr1;
+ PBufferOp BufferOp;
+
+ int Infile[MAX_FILE_NUMBER];
+ char *Infilename[MAX_FILE_NUMBER];
+
+ int intra_quantizer_matrix[64];
+ int non_intra_quantizer_matrix[64];
+ int chroma_intra_quantizer_matrix[64];
+ int chroma_non_intra_quantizer_matrix[64];
+
+ int load_intra_quantizer_matrix;
+ int load_non_intra_quantizer_matrix;
+ int load_chroma_intra_quantizer_matrix;
+ int load_chroma_non_intra_quantizer_matrix;
+
+ int q_scale_type;
+ int alternate_scan;
+ int quantizer_scale;
+
+ void *fTempArray, *p_fTempArray;
+ short *block[8], *p_block[8];
+ int pf_backward, pf_forward, pf_current;
+
+ // global values
+ unsigned char *backward_reference_frame[3], *forward_reference_frame[3];
+ unsigned char *auxframe[3], *current_frame[3];
+ unsigned char *u422, *v422, *u444, *v444, /* *rgb24,*/ *lum;
+ unsigned char *dstFrame; // replaces rgb24
+ __int64 RGB_Scale, RGB_Offset, RGB_CRV, RGB_CBU, RGB_CGX, LumOffsetMask, LumGainMask;
+
+ int HALF_WIDTH, PROGRESSIVE_HEIGHT, INTERLACED_HEIGHT, DOUBLE_WIDTH;
+ int /*TWIDTH, SWIDTH,*/ HALF_WIDTH_D8, LUM_AREA, CLIP_AREA, HALF_CLIP_AREA, CLIP_STEP;
+ int DSTBYTES, DSTBYTES2; // these replace TWIDTH and SWIDTH
public:
- int Clip_Width, Clip_Height, Resize_Width, Resize_Height;
+ int Clip_Width, Clip_Height, Resize_Width, Resize_Height;
protected:
- int Coded_Picture_Width, Coded_Picture_Height, Chroma_Width, Chroma_Height;
- int block_count, Second_Field;
- int horizontal_size, vertical_size, mb_width, mb_height;
-
- /* ISO/IEC 13818-2 section 6.2.2.3: sequence_extension() */
- int progressive_sequence;
- int chroma_format;
-
- /* ISO/IEC 13818-2 section 6.2.3: picture_header() */
- int picture_coding_type;
- int temporal_reference;
-
- /* ISO/IEC 13818-2 section 6.2.3.1: picture_coding_extension() header */
- int f_code[2][2];
- int picture_structure;
- int frame_pred_frame_dct;
- int progressive_frame;
- int concealment_motion_vectors;
- int intra_dc_precision;
- int top_field_first;
- int repeat_first_field;
- int intra_vlc_format;
-
- // interface
- typedef struct {
- DWORD number;
- int file;
- __int64 position;
- } GOPLIST;
- GOPLIST *GOPList[MAX_FRAME_NUMBER];
-
- typedef struct {
- DWORD top;
- DWORD bottom;
- char forward;
- char backward;
- } FRAMELIST;
- FRAMELIST *FrameList[MAX_FRAME_NUMBER];
-
- unsigned char *GOPBuffer[MAX_GOP_SIZE];
+ int Coded_Picture_Width, Coded_Picture_Height, Chroma_Width, Chroma_Height;
+ int block_count, Second_Field;
+ int horizontal_size, vertical_size, mb_width, mb_height;
+
+ /* ISO/IEC 13818-2 section 6.2.2.3: sequence_extension() */
+ int progressive_sequence;
+ int chroma_format;
+
+ /* ISO/IEC 13818-2 section 6.2.3: picture_header() */
+ int picture_coding_type;
+ int temporal_reference;
+
+ /* ISO/IEC 13818-2 section 6.2.3.1: picture_coding_extension() header */
+ int f_code[2][2];
+ int picture_structure;
+ int frame_pred_frame_dct;
+ int progressive_frame;
+ int concealment_motion_vectors;
+ int intra_dc_precision;
+ int top_field_first;
+ int repeat_first_field;
+ int intra_vlc_format;
+
+ // interface
+ typedef struct
+ {
+ DWORD number;
+ int file;
+ __int64 position;
+ } GOPLIST;
+ GOPLIST *GOPList[MAX_FRAME_NUMBER];
+
+ typedef struct
+ {
+ DWORD top;
+ DWORD bottom;
+ char forward;
+ char backward;
+ } FRAMELIST;
+ FRAMELIST *FrameList[MAX_FRAME_NUMBER];
+
+ unsigned char *GOPBuffer[MAX_GOP_SIZE];
public:
- BOOL Field_Order, Full_Frame;
+ BOOL Field_Order, Full_Frame;
protected:
- HINSTANCE hLibrary;
+ HINSTANCE hLibrary;
- void Copyodd(unsigned char *src, unsigned char *dst, int pitch, int forward);
- void Copyeven(unsigned char *src, unsigned char *dst, int pitch, int forward);
+ void Copyodd(unsigned char *src, unsigned char *dst, int pitch, int forward);
+ void Copyeven(unsigned char *src, unsigned char *dst, int pitch, int forward);
public:
- FILE *VF_File;
- int VF_FrameRate;
- DWORD VF_FrameLimit;
- DWORD VF_FrameBound;
- DWORD VF_GOPLimit;
- DWORD VF_GOPNow;
- DWORD VF_GOPSize;
- int VF_FrameSize;
- DWORD VF_OldFrame;
- DWORD VF_OldRef;
-
- enum DstFormat {
- RGB24, YUY2
- };
- DstFormat m_dstFormat;
-
- CMPEG2Dec();
- ~CMPEG2Dec() {Close();}
- int Open(LPCTSTR path, DstFormat);
- void Close();
- void Decode(unsigned char *dst, DWORD frame, int pitch);
- bool dstRGB24() const { return m_dstFormat == RGB24; }
- bool dstYUY2() const { return m_dstFormat == YUY2; }
+ FILE *VF_File;
+ int VF_FrameRate;
+ DWORD VF_FrameLimit;
+ DWORD VF_FrameBound;
+ DWORD VF_GOPLimit;
+ DWORD VF_GOPNow;
+ DWORD VF_GOPSize;
+ int VF_FrameSize;
+ DWORD VF_OldFrame;
+ DWORD VF_OldRef;
+
+ enum DstFormat
+ {
+ RGB24, YUY2
+ };
+ DstFormat m_dstFormat;
+
+ CMPEG2Dec();
+ ~CMPEG2Dec()
+ {
+ Close();
+ }
+ int Open(LPCTSTR path, DstFormat);
+ void Close();
+ void Decode(unsigned char *dst, DWORD frame, int pitch);
+ bool dstRGB24() const
+ {
+ return m_dstFormat == RGB24;
+ }
+ bool dstYUY2() const
+ {
+ return m_dstFormat == YUY2;
+ }
};
diff --git a/src/filters/source/D2VSource/idctfpu.cpp b/src/filters/source/D2VSource/idctfpu.cpp
index 92fcd3954..0b92b0315 100644
--- a/src/filters/source/D2VSource/idctfpu.cpp
+++ b/src/filters/source/D2VSource/idctfpu.cpp
@@ -33,7 +33,7 @@
#define FLOAT double
-const static double RC = 1.0*1024*1024*1024*1024*256*16 + 1024; // magic + clip center
+const static double RC = 1.0 * 1024 * 1024 * 1024 * 1024 * 256 * 16 + 1024; // magic + clip center
static FLOAT W1; // /* sqrt(2)*cos(1*pi/16) */
static FLOAT W2; // /* sqrt(2)*cos(2*pi/16) */
@@ -56,7 +56,7 @@ static FLOAT W2mW6; // W2-W6
static FLOAT W2pW6; // W2+W6
static FLOAT S2; // 1/sqrt(2)
-static FLOAT D8 = 1.0/8;
+static FLOAT D8 = 1.0 / 8;
static FLOAT W7_8;
static FLOAT W1mW7_8;
@@ -78,56 +78,62 @@ static short *iclp;
void Initialize_FPU_IDCT()
{
- int i;
-
- S2 = sqrt(0.5); // 1.0/sqrt(2);
-
- W1 = sqrt(2.0)*cos(PI*(1.0/16));
- W1_8 = W1/8;
- W2 = sqrt(2.0)*cos(PI*(2.0/16));
- W2_8 = W2/8;
- W3 = sqrt(2.0)*cos(PI*(3.0/16));
- W3_8 = W3/8;
- W5 = sqrt(2.0)*cos(PI*(5.0/16));
- W5_8 = W5/8;
- W6 = sqrt(2.0)*cos(PI*(6.0/16));
- W6_8 = W6/8;
- W7 = sqrt(2.0)*cos(PI*(7.0/16));
- W7_8 = W7/8;
-
- W1mW7 = W1-W7; W1mW7_8 = W1mW7/8;
- W1pW7 = W1+W7; W1pW7_8 = W1pW7/8;
- W3mW5 = W3-W5; W3mW5_8 = W3mW5/8;
- W3pW5 = W3+W5; W3pW5_8 = W3pW5/8;
- W2mW6 = W2-W6; W2mW6_8 = W2mW6/8;
- W2pW6 = W2+W6; W2pW6_8 = W2pW6/8;
-
- iclp = iclip+1024;
- for (i= -1024; i<1024; i++)
- iclp[i] = (i<-256) ? -256 : ((i>255) ? 255 : i);
+ int i;
+
+ S2 = sqrt(0.5); // 1.0/sqrt(2);
+
+ W1 = sqrt(2.0) * cos(PI * (1.0 / 16));
+ W1_8 = W1 / 8;
+ W2 = sqrt(2.0) * cos(PI * (2.0 / 16));
+ W2_8 = W2 / 8;
+ W3 = sqrt(2.0) * cos(PI * (3.0 / 16));
+ W3_8 = W3 / 8;
+ W5 = sqrt(2.0) * cos(PI * (5.0 / 16));
+ W5_8 = W5 / 8;
+ W6 = sqrt(2.0) * cos(PI * (6.0 / 16));
+ W6_8 = W6 / 8;
+ W7 = sqrt(2.0) * cos(PI * (7.0 / 16));
+ W7_8 = W7 / 8;
+
+ W1mW7 = W1 - W7;
+ W1mW7_8 = W1mW7 / 8;
+ W1pW7 = W1 + W7;
+ W1pW7_8 = W1pW7 / 8;
+ W3mW5 = W3 - W5;
+ W3mW5_8 = W3mW5 / 8;
+ W3pW5 = W3 + W5;
+ W3pW5_8 = W3pW5 / 8;
+ W2mW6 = W2 - W6;
+ W2mW6_8 = W2mW6 / 8;
+ W2pW6 = W2 + W6;
+ W2pW6_8 = W2pW6 / 8;
+
+ iclp = iclip + 1024;
+ for(i = -1024; i < 1024; i++)
+ iclp[i] = (i < -256) ? -256 : ((i > 255) ? 255 : i);
}
void FPU_IDCT(short *block)
{
- int *b = (int *) block;
- if( b[0]==0 && (b[31]==0x10000 || b[31]==0) )
- {
- if( b[ 1]|b[ 2]|b[ 3]|b[ 4]|b[ 5] )
- goto normal;
- if( b[ 6]|b[ 7]|b[ 8]|b[ 9]|b[10] )
- goto normal;
- if( b[11]|b[12]|b[13]|b[14]|b[15] )
- goto normal;
- if( b[16]|b[17]|b[18]|b[19]|b[20] )
- goto normal;
- if( b[21]|b[22]|b[23]|b[24]|b[25] )
- goto normal;
- if( b[26]|b[27]|b[28]|b[29]|b[30] )
- goto normal;
- b[31]=0;
- ////empty++;
- return;
- }
+ int *b = (int *) block;
+ if(b[0] == 0 && (b[31] == 0x10000 || b[31] == 0))
+ {
+ if(b[ 1] | b[ 2] | b[ 3] | b[ 4] | b[ 5])
+ goto normal;
+ if(b[ 6] | b[ 7] | b[ 8] | b[ 9] | b[10])
+ goto normal;
+ if(b[11] | b[12] | b[13] | b[14] | b[15])
+ goto normal;
+ if(b[16] | b[17] | b[18] | b[19] | b[20])
+ goto normal;
+ if(b[21] | b[22] | b[23] | b[24] | b[25])
+ goto normal;
+ if(b[26] | b[27] | b[28] | b[29] | b[30])
+ goto normal;
+ b[31] = 0;
+ ////empty++;
+ return;
+ }
normal:
#define tmp ebx
@@ -143,314 +149,314 @@ normal:
#define int6 ebx-3*8-7*4
#define int7 ebx-3*8-8*4
#define SIZE 8*8*8+3*8+8*4+16 // locals + 16-byte alignment area
- __asm
- {
- lea ebx,[esp-8*8*8]
- sub esp,SIZE
- and ebx,-16 // force 16-byte alignment of locals
+ __asm
+ {
+ lea ebx, [esp-8*8*8]
+ sub esp, SIZE
+ and ebx, -16 // force 16-byte alignment of locals
// rows
- mov esi,[block]
- lea edi,[tmp]
- mov ecx,8
-
- align 16
-Lrows:
- movsx eax,word ptr [esi+2]
- or eax, [esi+4]
- or eax, [esi+8]
- or eax, [esi+12]
- jnz L1
-
- fild word ptr [esi+0*2]
- fst qword ptr [edi+7*8]
- fst qword ptr [edi+6*8]
- fst qword ptr [edi+5*8]
- fst qword ptr [edi+4*8]
- fst qword ptr [edi+3*8]
- fst qword ptr [edi+2*8]
- fst qword ptr [edi+1*8]
- fstp qword ptr [edi+0*8]
- jmp L2
-
- align 16
- L1:
-
- fild word ptr [esi+7*2]
- fld st(0)
- fild word ptr [esi+1*2]
- fadd st(1),st(0)
- fld qword ptr [W7]
- fxch st(1)
- fmul qword ptr [W1mW7]
- fxch st(1)
- fmulp st(2),st(0)
- fadd st(0),st(1)
- fstp qword ptr [tmp1]
- fild word ptr [esi+3*2]
- fld st(0)
- fxch st(3)
- fmul qword ptr [W1pW7]
- fild word ptr [esi+5*2]
- fadd st(4),st(0)
- fmul qword ptr [W3mW5]
- fxch st(1)
- fsubp st(3),st(0)//fsubrp
- fld qword ptr [W3]
- fmulp st(4),st(0)
- fsubr st(0),st(3)
- fstp qword ptr [tmp2]
- fmul qword ptr [W3pW5]
- fsubp st(2),st(0)//fsubrp
- fxch st(1)
- fstp qword ptr [tmp3]
- fild word ptr [esi+0*2]
- fild word ptr [esi+4*2]
- fild word ptr [esi+2*2]
- fld st(0)
- fmul qword ptr [W2mW6]
- fld st(3)
- fild word ptr [esi+6*2]
- fxch st(5)
- fsub st(0),st(4)
- fxch st(3)
- fadd st(0),st(5)
- fxch st(1)
- faddp st(4),st(0)
- fld qword ptr [W6]
- fmulp st(1),st(0)
- fxch st(4)
- fmul qword ptr [W2pW6]
- fld qword ptr [tmp1]
- fsub qword ptr [tmp2]
- fld st(5)
- fxch st(3)
- faddp st(6),st(0)
- fld qword ptr [tmp1]
- fxch st(1)
- fstp qword ptr [tmp1]
- fld st(6)
- fadd qword ptr [tmp3]
- fxch st(1)
- fadd qword ptr [tmp2]
- fxch st(7)
- fsub qword ptr [tmp3]
- fxch st(1)
- fstp qword ptr [tmp2]
- fld st(4)
- fxch st(3)
- fsubrp st(2),st(0)//fsubp
- fxch st(4)
- fsub st(0),st(5)
- fxch st(2)
- faddp st(5),st(0)
- fld st(2)
- fsub st(0),st(1)
- fxch st(5)
- fstp qword ptr [tmp3]
- fld qword ptr [tmp1]
- fld qword ptr [S2]
- fxch st(4)
- faddp st(2),st(0)
- fld st(3)
- fxch st(1)
- fadd st(0),st(5)
- fmulp st(1),st(0)
-
- fld qword ptr [tmp3]
- fadd st(0),st(7)
- fxch st(5)
- fsubr qword ptr [tmp1]
- fxch st(5)
- fstp qword ptr [edi+0*8]
- fxch st(6)
- fsubr qword ptr [tmp3]
- fld st(2)
- fxch st(1)
- fstp qword ptr [edi+7*8]
- fadd qword ptr [tmp2]
- fxch st(3)
- fmulp st(4),st(0)
- fxch st(2)
- fstp qword ptr [edi+3*8]
- fld st(1)
- fadd st(0),st(5)
- fxch st(1)
- fsub qword ptr [tmp2]
- fxch st(2)
- fsubrp st(5),st(0)//fsubp
- fstp qword ptr [edi+1*8]
- fld st(2)
- fxch st(1)
- fstp qword ptr [edi+4*8]
- fxch st(2)
- fsub st(0),st(1)
- fxch st(2)
- faddp st(1),st(0)
- fxch st(2)
- fstp qword ptr [edi+6*8]
- fstp qword ptr [edi+5*8]
- fstp qword ptr [edi+2*8]
- L2:
- add esi,8*2
- add edi,8*8
- dec ecx
- jnz Lrows
+ mov esi, [block]
+ lea edi, [tmp]
+ mov ecx, 8
+
+ align 16
+ Lrows:
+ movsx eax, word ptr [esi+2]
+ or eax, [esi+4]
+ or eax, [esi+8]
+ or eax, [esi+12]
+ jnz L1
+
+ fild word ptr [esi+0*2]
+ fst qword ptr [edi+7*8]
+ fst qword ptr [edi+6*8]
+ fst qword ptr [edi+5*8]
+ fst qword ptr [edi+4*8]
+ fst qword ptr [edi+3*8]
+ fst qword ptr [edi+2*8]
+ fst qword ptr [edi+1*8]
+ fstp qword ptr [edi+0*8]
+ jmp L2
+
+ align 16
+ L1:
+
+ fild word ptr [esi+7*2]
+ fld st(0)
+ fild word ptr [esi+1*2]
+ fadd st(1), st(0)
+ fld qword ptr [W7]
+ fxch st(1)
+ fmul qword ptr [W1mW7]
+ fxch st(1)
+ fmulp st(2), st(0)
+ fadd st(0), st(1)
+ fstp qword ptr [tmp1]
+ fild word ptr [esi+3*2]
+ fld st(0)
+ fxch st(3)
+ fmul qword ptr [W1pW7]
+ fild word ptr [esi+5*2]
+ fadd st(4), st(0)
+ fmul qword ptr [W3mW5]
+ fxch st(1)
+ fsubp st(3), st(0) //fsubrp
+ fld qword ptr [W3]
+ fmulp st(4), st(0)
+ fsubr st(0), st(3)
+ fstp qword ptr [tmp2]
+ fmul qword ptr [W3pW5]
+ fsubp st(2), st(0) //fsubrp
+ fxch st(1)
+ fstp qword ptr [tmp3]
+ fild word ptr [esi+0*2]
+ fild word ptr [esi+4*2]
+ fild word ptr [esi+2*2]
+ fld st(0)
+ fmul qword ptr [W2mW6]
+ fld st(3)
+ fild word ptr [esi+6*2]
+ fxch st(5)
+ fsub st(0), st(4)
+ fxch st(3)
+ fadd st(0), st(5)
+ fxch st(1)
+ faddp st(4), st(0)
+ fld qword ptr [W6]
+ fmulp st(1), st(0)
+ fxch st(4)
+ fmul qword ptr [W2pW6]
+ fld qword ptr [tmp1]
+ fsub qword ptr [tmp2]
+ fld st(5)
+ fxch st(3)
+ faddp st(6), st(0)
+ fld qword ptr [tmp1]
+ fxch st(1)
+ fstp qword ptr [tmp1]
+ fld st(6)
+ fadd qword ptr [tmp3]
+ fxch st(1)
+ fadd qword ptr [tmp2]
+ fxch st(7)
+ fsub qword ptr [tmp3]
+ fxch st(1)
+ fstp qword ptr [tmp2]
+ fld st(4)
+ fxch st(3)
+ fsubrp st(2), st(0) //fsubp
+ fxch st(4)
+ fsub st(0), st(5)
+ fxch st(2)
+ faddp st(5), st(0)
+ fld st(2)
+ fsub st(0), st(1)
+ fxch st(5)
+ fstp qword ptr [tmp3]
+ fld qword ptr [tmp1]
+ fld qword ptr [S2]
+ fxch st(4)
+ faddp st(2), st(0)
+ fld st(3)
+ fxch st(1)
+ fadd st(0), st(5)
+ fmulp st(1), st(0)
+
+ fld qword ptr [tmp3]
+ fadd st(0), st(7)
+ fxch st(5)
+ fsubr qword ptr [tmp1]
+ fxch st(5)
+ fstp qword ptr [edi+0*8]
+ fxch st(6)
+ fsubr qword ptr [tmp3]
+ fld st(2)
+ fxch st(1)
+ fstp qword ptr [edi+7*8]
+ fadd qword ptr [tmp2]
+ fxch st(3)
+ fmulp st(4), st(0)
+ fxch st(2)
+ fstp qword ptr [edi+3*8]
+ fld st(1)
+ fadd st(0), st(5)
+ fxch st(1)
+ fsub qword ptr [tmp2]
+ fxch st(2)
+ fsubrp st(5), st(0) //fsubp
+ fstp qword ptr [edi+1*8]
+ fld st(2)
+ fxch st(1)
+ fstp qword ptr [edi+4*8]
+ fxch st(2)
+ fsub st(0), st(1)
+ fxch st(2)
+ faddp st(1), st(0)
+ fxch st(2)
+ fstp qword ptr [edi+6*8]
+ fstp qword ptr [edi+5*8]
+ fstp qword ptr [edi+2*8]
+ L2:
+ add esi, 8*2
+ add edi, 8*8
+ dec ecx
+ jnz Lrows
// columns
- lea esi,[tmp]
- mov edi,[block]
- lea edx,[iclip+1024*2]
- mov ecx,8
-
- align 16
-Lcols:
- fld qword ptr [esi+7*8*8]
- fld st(0)
- fld qword ptr [esi+1*8*8]
- fadd st(1),st(0)
- fld qword ptr [W7_8]
- fxch st(1)
- fmul qword ptr [W1mW7_8]
- fxch st(1)
- fmulp st(2),st(0)
- fadd st(0),st(1)
- fstp qword ptr [tmp2]
- fld qword ptr [esi+3*8*8]
- fld st(0)
- fxch st(3)
- fmul qword ptr [W1pW7_8]
- fld qword ptr [esi+5*8*8]
- fadd st(4),st(0)
- fmul qword ptr [W3mW5_8]
- fxch st(1)
- fsubp st(3),st(0)//fsubrp
- fld qword ptr [W3_8]
- fmulp st(4),st(0)
- fsubr st(0),st(3)
- fstp qword ptr [tmp3]
- fld qword ptr [D8]
- fld qword ptr [esi+0*8*8]
- fmul st(0),st(1)
- fxch st(2)
- fmul qword ptr [W3pW5_8]
- fld qword ptr [esi+4*8*8]
- fmulp st(2),st(0)
- fld qword ptr [esi+6*8*8]
- fld st(3)
- fxch st(6)
- fsubrp st(2),st(0)//fsubp
- fld qword ptr [esi+2*8*8]
- fld st(0)
- fxch st(5)
- fsub st(0),st(4)
- fxch st(7)
- faddp st(4),st(0)
- fxch st(4)
- fadd st(0),st(1)
- fld qword ptr [W6_8]
- fxch st(2)
- fmul qword ptr [W2pW6_8]
- fxch st(2)
- fmulp st(1),st(0)
- fxch st(4)
- fmul qword ptr [W2mW6_8]
- fld qword ptr [tmp2]
- fsub qword ptr [tmp3]
- fxch st(2)
- fsubr st(0),st(5)
- fxch st(1)
- faddp st(5),st(0)
- fld qword ptr [tmp2]
- fxch st(2)
- fstp qword ptr [tmp2]
- fld st(5)
- fxch st(2)
- fadd qword ptr [tmp3]
- fxch st(6)
- fsub st(0),st(3)
- fxch st(2)
- faddp st(3),st(0)
- fld st(3)
- fsub st(0),st(5)
- fxch st(3)
- fstp qword ptr [tmp3]
- fxch st(3)
- faddp st(4),st(0)
- fld st(5)
- fld qword ptr [tmp2]
- fxch st(7)
- fsub st(0),st(4)
- fxch st(7)
- fadd st(0),st(2)
- fxch st(1)
- faddp st(4),st(0)
- fld qword ptr [S2]
- fmul st(1),st(0)
- fxch st(1)
- fstp qword ptr [tmp1]
- fld st(4)
- fadd st(0),st(6)
- fxch st(2)
- fsubr qword ptr [tmp2]
- fxch st(5)
- fsubrp st(6),st(0)//fsubp
- fxch st(1)
- fistp dword ptr [int0]
- fxch st(4)
- mov eax,[int0]
- movsx eax,word ptr [edx+2*eax]
- mov [edi+0*8*2],ax
- fistp dword ptr [int7]
- mov eax,[int7]
- fld st(0)
- movsx eax,word ptr [edx+2*eax]
- mov [edi+7*8*2],ax
- fadd qword ptr [tmp3]
- fistp dword ptr [int3]
- mov eax,[int3]
- movsx eax,word ptr [edx+2*eax]
- mov [edi+3*8*2],ax
- fsub qword ptr [tmp3]
- fld st(1)
- fxch st(1)
- fistp dword ptr [int4]
- mov eax,[int4]
- movsx eax,word ptr [edx+2*eax]
- mov [edi+4*8*2],ax
- fadd qword ptr [tmp1]
- fxch st(3)
- fmulp st(2),st(0)
- fxch st(2)
- fistp dword ptr [int1]
- fxch st(1)
- mov eax,[int1]
- movsx eax,word ptr [edx+2*eax]
- mov [edi+1*8*2],ax
- fsub qword ptr [tmp1]
- fld st(2)
- fsub st(0),st(2)
- fxch st(1)
- fistp dword ptr [int6]
- fxch st(2)
- mov eax,[int6]
- faddp st(1),st(0)
- movsx eax,word ptr [edx+2*eax]
- mov [edi+6*8*2],ax
- fistp dword ptr [int2]
- mov eax,[int2]
- movsx eax,word ptr [edx+2*eax]
- mov [edi+2*8*2],ax
- fistp dword ptr [int5]
- mov eax,[int5]
- movsx eax,word ptr [edx+2*eax]
- mov [edi+5*8*2],ax
-
- add esi,8
- add edi,2
- dec ecx
- jnz Lcols
-
- add esp,SIZE
- }
+ lea esi, [tmp]
+ mov edi, [block]
+ lea edx, [iclip+1024*2]
+ mov ecx, 8
+
+ align 16
+ Lcols:
+ fld qword ptr [esi+7*8*8]
+ fld st(0)
+ fld qword ptr [esi+1*8*8]
+ fadd st(1), st(0)
+ fld qword ptr [W7_8]
+ fxch st(1)
+ fmul qword ptr [W1mW7_8]
+ fxch st(1)
+ fmulp st(2), st(0)
+ fadd st(0), st(1)
+ fstp qword ptr [tmp2]
+ fld qword ptr [esi+3*8*8]
+ fld st(0)
+ fxch st(3)
+ fmul qword ptr [W1pW7_8]
+ fld qword ptr [esi+5*8*8]
+ fadd st(4), st(0)
+ fmul qword ptr [W3mW5_8]
+ fxch st(1)
+ fsubp st(3), st(0) //fsubrp
+ fld qword ptr [W3_8]
+ fmulp st(4), st(0)
+ fsubr st(0), st(3)
+ fstp qword ptr [tmp3]
+ fld qword ptr [D8]
+ fld qword ptr [esi+0*8*8]
+ fmul st(0), st(1)
+ fxch st(2)
+ fmul qword ptr [W3pW5_8]
+ fld qword ptr [esi+4*8*8]
+ fmulp st(2), st(0)
+ fld qword ptr [esi+6*8*8]
+ fld st(3)
+ fxch st(6)
+ fsubrp st(2), st(0) //fsubp
+ fld qword ptr [esi+2*8*8]
+ fld st(0)
+ fxch st(5)
+ fsub st(0), st(4)
+ fxch st(7)
+ faddp st(4), st(0)
+ fxch st(4)
+ fadd st(0), st(1)
+ fld qword ptr [W6_8]
+ fxch st(2)
+ fmul qword ptr [W2pW6_8]
+ fxch st(2)
+ fmulp st(1), st(0)
+ fxch st(4)
+ fmul qword ptr [W2mW6_8]
+ fld qword ptr [tmp2]
+ fsub qword ptr [tmp3]
+ fxch st(2)
+ fsubr st(0), st(5)
+ fxch st(1)
+ faddp st(5), st(0)
+ fld qword ptr [tmp2]
+ fxch st(2)
+ fstp qword ptr [tmp2]
+ fld st(5)
+ fxch st(2)
+ fadd qword ptr [tmp3]
+ fxch st(6)
+ fsub st(0), st(3)
+ fxch st(2)
+ faddp st(3), st(0)
+ fld st(3)
+ fsub st(0), st(5)
+ fxch st(3)
+ fstp qword ptr [tmp3]
+ fxch st(3)
+ faddp st(4), st(0)
+ fld st(5)
+ fld qword ptr [tmp2]
+ fxch st(7)
+ fsub st(0), st(4)
+ fxch st(7)
+ fadd st(0), st(2)
+ fxch st(1)
+ faddp st(4), st(0)
+ fld qword ptr [S2]
+ fmul st(1), st(0)
+ fxch st(1)
+ fstp qword ptr [tmp1]
+ fld st(4)
+ fadd st(0), st(6)
+ fxch st(2)
+ fsubr qword ptr [tmp2]
+ fxch st(5)
+ fsubrp st(6), st(0) //fsubp
+ fxch st(1)
+ fistp dword ptr [int0]
+ fxch st(4)
+ mov eax, [int0]
+ movsx eax, word ptr [edx+2*eax]
+ mov [edi+0*8*2], ax
+ fistp dword ptr [int7]
+ mov eax, [int7]
+ fld st(0)
+ movsx eax, word ptr [edx+2*eax]
+ mov [edi+7*8*2], ax
+ fadd qword ptr [tmp3]
+ fistp dword ptr [int3]
+ mov eax, [int3]
+ movsx eax, word ptr [edx+2*eax]
+ mov [edi+3*8*2], ax
+ fsub qword ptr [tmp3]
+ fld st(1)
+ fxch st(1)
+ fistp dword ptr [int4]
+ mov eax, [int4]
+ movsx eax, word ptr [edx+2*eax]
+ mov [edi+4*8*2], ax
+ fadd qword ptr [tmp1]
+ fxch st(3)
+ fmulp st(2), st(0)
+ fxch st(2)
+ fistp dword ptr [int1]
+ fxch st(1)
+ mov eax, [int1]
+ movsx eax, word ptr [edx+2*eax]
+ mov [edi+1*8*2], ax
+ fsub qword ptr [tmp1]
+ fld st(2)
+ fsub st(0), st(2)
+ fxch st(1)
+ fistp dword ptr [int6]
+ fxch st(2)
+ mov eax, [int6]
+ faddp st(1), st(0)
+ movsx eax, word ptr [edx+2*eax]
+ mov [edi+6*8*2], ax
+ fistp dword ptr [int2]
+ mov eax, [int2]
+ movsx eax, word ptr [edx+2*eax]
+ mov [edi+2*8*2], ax
+ fistp dword ptr [int5]
+ mov eax, [int5]
+ movsx eax, word ptr [edx+2*eax]
+ mov [edi+5*8*2], ax
+
+ add esi, 8
+ add edi, 2
+ dec ecx
+ jnz Lcols
+
+ add esp, SIZE
+ }
}
diff --git a/src/filters/source/D2VSource/idctref.cpp b/src/filters/source/D2VSource/idctref.cpp
index 74b695ce1..2c1024692 100644
--- a/src/filters/source/D2VSource/idctref.cpp
+++ b/src/filters/source/D2VSource/idctref.cpp
@@ -40,323 +40,323 @@ static double c[8][8];
/* initialize DCT coefficient matrix */
void Initialize_REF_IDCT()
{
- int freq, time, i;
- double scale;
+ int freq, time, i;
+ double scale;
- for (freq=0; freq < 8; freq++)
- {
- scale = (freq == 0) ? sqrt(0.125) : 0.5;
- for (time=0; time<8; time++)
- c[freq][time] = scale*cos((M_PI/8.0)*freq*(time + 0.5));
- }
+ for(freq = 0; freq < 8; freq++)
+ {
+ scale = (freq == 0) ? sqrt(0.125) : 0.5;
+ for(time = 0; time < 8; time++)
+ c[freq][time] = scale * cos((M_PI / 8.0) * freq * (time + 0.5));
+ }
#ifdef ModelX
- iclp = iclip+1024;
- for (i= -1024; i<1024; i++)
- iclp[i] = (i<-256) ? -256 : ((i>255) ? 255 : i);
+ iclp = iclip + 1024;
+ for(i = -1024; i < 1024; i++)
+ iclp[i] = (i < -256) ? -256 : ((i > 255) ? 255 : i);
#endif
}
void REF_IDCT(short *block)
{
- double tmp[64];
- double rnd[64];
- int int0, int1, int2, int3, int4, int5, int6, int7;
- unsigned short fpold;
- unsigned short fpnew;
-
- int *b = (int *) block;
-
- if( !(b[0]|(b[31]&~0x10000)) )
- {
- if( b[ 1]|b[ 2]|b[ 3]|b[ 4]|b[ 5]|b[ 6] )
- goto normal;
- if( b[ 7]|b[ 8]|b[ 9]|b[10]|b[11]|b[12] )
- goto normal;
- if( b[13]|b[14]|b[15]|b[16]|b[17]|b[18] )
- goto normal;
- if( b[19]|b[20]|b[21]|b[22]|b[23]|b[24] )
- goto normal;
- if( b[25]|b[26]|b[27]|b[28]|b[29]|b[30] )
- goto normal;
- b[31]=0;
- return;
- }
+ double tmp[64];
+ double rnd[64];
+ int int0, int1, int2, int3, int4, int5, int6, int7;
+ unsigned short fpold;
+ unsigned short fpnew;
+
+ int *b = (int *) block;
+
+ if(!(b[0] | (b[31]&~0x10000)))
+ {
+ if(b[ 1] | b[ 2] | b[ 3] | b[ 4] | b[ 5] | b[ 6])
+ goto normal;
+ if(b[ 7] | b[ 8] | b[ 9] | b[10] | b[11] | b[12])
+ goto normal;
+ if(b[13] | b[14] | b[15] | b[16] | b[17] | b[18])
+ goto normal;
+ if(b[19] | b[20] | b[21] | b[22] | b[23] | b[24])
+ goto normal;
+ if(b[25] | b[26] | b[27] | b[28] | b[29] | b[30])
+ goto normal;
+ b[31] = 0;
+ return;
+ }
normal:
- __asm
- {
- // do the IDCT
- mov esi,[block]
- lea eax,[c]
- lea edi,[tmp]
- //mov ebx,8
- mov ebx,8 // 0x77000000 // 8
- align 16
- __col1:
- movzx edx,[esi+1*2]
- mov ecx,[esi+2*2]
- or edx,[esi+4*2]
- or ecx,[esi+6*2]
- or edx,ecx
- //mov ecx,8
- mov ecx,8/2 // 0x77000000 // 8
-
- jnz __row1
- fild word ptr [esi+0*2]
- fmul qword ptr [eax+0*8*8]
- fst qword ptr [edi+0*8]
- fst qword ptr [edi+1*8]
- fst qword ptr [edi+2*8]
- fst qword ptr [edi+3*8]
- fst qword ptr [edi+4*8]
- fst qword ptr [edi+5*8]
- fst qword ptr [edi+6*8]
- fstp qword ptr [edi+7*8]
- add edi,8*8
- jmp __next1
- align 16
- __row1:
- fild word ptr [esi+0*2]
- fmul qword ptr [eax+0*8*8]
- fild word ptr [esi+1*2]
- fmul qword ptr [eax+1*8*8]
- fadd
- fild word ptr [esi+2*2]
- fmul qword ptr [eax+2*8*8]
- fadd
- fild word ptr [esi+3*2]
- fmul qword ptr [eax+3*8*8]
- fadd
- fild word ptr [esi+4*2]
- fmul qword ptr [eax+4*8*8]
- fadd
- fild word ptr [esi+5*2]
- fmul qword ptr [eax+5*8*8]
- fadd
- fild word ptr [esi+6*2]
- fmul qword ptr [eax+6*8*8]
- fadd
- fild word ptr [esi+7*2]
- fmul qword ptr [eax+7*8*8]
- fadd
-
- fild word ptr [esi+0*2]
- fmul qword ptr [eax+0*8*8+8]
- fild word ptr [esi+1*2]
- fmul qword ptr [eax+1*8*8+8]
- fadd
- fild word ptr [esi+2*2]
- fmul qword ptr [eax+2*8*8+8]
- fadd
- fild word ptr [esi+3*2]
- fmul qword ptr [eax+3*8*8+8]
- fadd
- fild word ptr [esi+4*2]
- fmul qword ptr [eax+4*8*8+8]
- fadd
- fild word ptr [esi+5*2]
- fmul qword ptr [eax+5*8*8+8]
- fadd
- fild word ptr [esi+6*2]
- fmul qword ptr [eax+6*8*8+8]
- fadd
- fild word ptr [esi+7*2]
- fmul qword ptr [eax+7*8*8+8]
- fadd
- add eax,8*2
- fxch st(1)
- fstp qword ptr [edi]//
- fstp qword ptr [edi+8]
- add edi,8*2
- dec ecx
-
- jnz __row1
- add eax,-8*8
- //align 16
- __next1:
- add esi,+8*2
-
- sub ebx,0x80000001 // add ebx,ebx
- js __col1
- //align 16
- test ebx,ebx // align jump &| redo flags
- jnz __col1
-
- lea esi,[tmp]
- lea eax,[c]
- lea edi,[rnd]
- //mov edi,[block]
- fld qword ptr [HALF]
- mov ebx,8
- __row2:
- mov ecx,8/2
- align 16
- __col2:
- fld qword ptr [esi+0*8*8]
- fmul qword ptr [eax+0*8*8]
- fld qword ptr [esi+1*8*8]
- fmul qword ptr [eax+1*8*8]
- fadd
- fld qword ptr [esi+2*8*8]
- fmul qword ptr [eax+2*8*8]
- fadd
- fld qword ptr [esi+3*8*8]
- fmul qword ptr [eax+3*8*8]
- fadd
- fld qword ptr [esi+4*8*8]
- fmul qword ptr [eax+4*8*8]
- fadd
- fld qword ptr [esi+5*8*8]
- fmul qword ptr [eax+5*8*8]
- fadd
- fld qword ptr [esi+6*8*8]
- fmul qword ptr [eax+6*8*8]
- fadd
- fld qword ptr [esi+7*8*8]
- fmul qword ptr [eax+7*8*8]
- fadd
- fadd st(0),st(1)
-
- fxch st(1)
-
- fld qword ptr [esi+0*8*8]
- fmul qword ptr [eax+0*8*8+8]
- fld qword ptr [esi+1*8*8]
- fmul qword ptr [eax+1*8*8+8]
- fadd
- fld qword ptr [esi+2*8*8]
- fmul qword ptr [eax+2*8*8+8]
- fadd
- fld qword ptr [esi+3*8*8]
- fmul qword ptr [eax+3*8*8+8]
- fadd
- fld qword ptr [esi+4*8*8]
- fmul qword ptr [eax+4*8*8+8]
- fadd
- fld qword ptr [esi+5*8*8]
- fmul qword ptr [eax+5*8*8+8]
- fadd
- fld qword ptr [esi+6*8*8]
- fmul qword ptr [eax+6*8*8+8]
- fadd
- fld qword ptr [esi+7*8*8]
- fmul qword ptr [eax+7*8*8+8]
- fadd
- fadd st(0),st(1)
- add eax,8*2
-
- fxch st(2)
- fstp qword ptr [edi]
- fxch st(1)
- fstp qword ptr [edi+8*8]
- add edi,8*8*2
-
- dec ecx
-
- jnz __col2
- add eax,-8*8
- add esi,+8
- add edi,8-8*8*8
-
- sub ebx,0x80000001
- js __row2
- //align 16
- test ebx,ebx // align jump &| redo flags
- jnz __row2
- ffree st(0) // bye bye 0.5
-
- // set x87 to floor mode
- fstcw [fpold]
- movzx eax, [fpold]
-
- or eax, 0x0400 // round down - floor
- mov [fpnew], ax
- fldcw [fpnew]
-
- // now floor the damn array
- lea esi, [rnd]
- mov edi, [block]
- mov ebx, -256 // clip min
- mov edx, +255 // clip max
- mov ecx, 8
- align 16
- __floor:
- fld qword ptr [esi+0*8]
- fistp dword ptr [int0]
- mov eax,[int0]
- cmp eax,ebx
- cmovl eax,ebx
- cmp eax,edx
- cmovg eax,edx
- fld qword ptr [esi+1*8]
- fistp dword ptr [int1]
- mov word ptr [edi+0*2],ax
- mov eax,[int1]
- cmp eax,ebx
- cmovl eax,ebx
- cmp eax,edx
- cmovg eax,edx
- fld qword ptr [esi+2*8]
- fistp dword ptr [int2]
- mov word ptr [edi+1*2],ax
- mov eax,[int2]
- cmp eax,ebx
- cmovl eax,ebx
- cmp eax,edx
- cmovg eax,edx
- fld qword ptr [esi+3*8]
- fistp dword ptr [int3]
- mov word ptr [edi+2*2],ax
- mov eax,[int3]
- cmp eax,ebx
- cmovl eax,ebx
- cmp eax,edx
- cmovg eax,edx
- fld qword ptr [esi+4*8]
- fistp dword ptr [int4]
- mov word ptr [edi+3*2],ax
- mov eax,[int4]
- cmp eax,ebx
- cmovl eax,ebx
- cmp eax,edx
- cmovg eax,edx
- fld qword ptr [esi+5*8]
- fistp dword ptr [int5]
- mov word ptr [edi+4*2],ax
- mov eax,[int5]
- cmp eax,ebx
- cmovl eax,ebx
- cmp eax,edx
- cmovg eax,edx
- fld qword ptr [esi+6*8]
- fistp dword ptr [int6]
- mov word ptr [edi+5*2],ax
- mov eax,[int6]
- cmp eax,ebx
- cmovl eax,ebx
- cmp eax,edx
- cmovg eax,edx
- fld qword ptr [esi+7*8]
- fistp dword ptr [int7]
- mov word ptr [edi+6*2],ax
- mov eax,[int7]
- cmp eax,ebx
- cmovl eax,ebx
- cmp eax,edx
- cmovg eax,edx
- mov word ptr [edi+7*2],ax
-
- add esi, 8*8
- add edi, 8*2
-
- sub ecx,0x80000001
- js __floor
- //align 16
- test ecx,ecx // align jump &| redo flags
- jnz __floor
-
- // set x87 to default mode
- fldcw [fpold]
- };
+ __asm
+ {
+ // do the IDCT
+ mov esi, [block]
+ lea eax, [c]
+ lea edi, [tmp]
+ //mov ebx,8
+ mov ebx, 8 // 0x77000000 // 8
+ align 16
+ __col1:
+ movzx edx, [esi+1*2]
+ mov ecx, [esi+2*2]
+ or edx, [esi+4*2]
+ or ecx, [esi+6*2]
+ or edx, ecx
+ //mov ecx,8
+ mov ecx, 8/2 // 0x77000000 // 8
+
+ jnz __row1
+ fild word ptr [esi+0*2]
+ fmul qword ptr [eax+0*8*8]
+ fst qword ptr [edi+0*8]
+ fst qword ptr [edi+1*8]
+ fst qword ptr [edi+2*8]
+ fst qword ptr [edi+3*8]
+ fst qword ptr [edi+4*8]
+ fst qword ptr [edi+5*8]
+ fst qword ptr [edi+6*8]
+ fstp qword ptr [edi+7*8]
+ add edi, 8*8
+ jmp __next1
+ align 16
+ __row1:
+ fild word ptr [esi+0*2]
+ fmul qword ptr [eax+0*8*8]
+ fild word ptr [esi+1*2]
+ fmul qword ptr [eax+1*8*8]
+ fadd
+ fild word ptr [esi+2*2]
+ fmul qword ptr [eax+2*8*8]
+ fadd
+ fild word ptr [esi+3*2]
+ fmul qword ptr [eax+3*8*8]
+ fadd
+ fild word ptr [esi+4*2]
+ fmul qword ptr [eax+4*8*8]
+ fadd
+ fild word ptr [esi+5*2]
+ fmul qword ptr [eax+5*8*8]
+ fadd
+ fild word ptr [esi+6*2]
+ fmul qword ptr [eax+6*8*8]
+ fadd
+ fild word ptr [esi+7*2]
+ fmul qword ptr [eax+7*8*8]
+ fadd
+
+ fild word ptr [esi+0*2]
+ fmul qword ptr [eax+0*8*8+8]
+ fild word ptr [esi+1*2]
+ fmul qword ptr [eax+1*8*8+8]
+ fadd
+ fild word ptr [esi+2*2]
+ fmul qword ptr [eax+2*8*8+8]
+ fadd
+ fild word ptr [esi+3*2]
+ fmul qword ptr [eax+3*8*8+8]
+ fadd
+ fild word ptr [esi+4*2]
+ fmul qword ptr [eax+4*8*8+8]
+ fadd
+ fild word ptr [esi+5*2]
+ fmul qword ptr [eax+5*8*8+8]
+ fadd
+ fild word ptr [esi+6*2]
+ fmul qword ptr [eax+6*8*8+8]
+ fadd
+ fild word ptr [esi+7*2]
+ fmul qword ptr [eax+7*8*8+8]
+ fadd
+ add eax, 8*2
+ fxch st(1)
+ fstp qword ptr [edi]//
+ fstp qword ptr [edi+8]
+ add edi, 8*2
+ dec ecx
+
+ jnz __row1
+ add eax, -8*8
+ //align 16
+ __next1:
+ add esi, +8*2
+
+ sub ebx, 0x80000001 // add ebx,ebx
+ js __col1
+ //align 16
+ test ebx, ebx // align jump &| redo flags
+ jnz __col1
+
+ lea esi, [tmp]
+ lea eax, [c]
+ lea edi, [rnd]
+ //mov edi,[block]
+ fld qword ptr [HALF]
+ mov ebx, 8
+ __row2:
+ mov ecx, 8/2
+ align 16
+ __col2:
+ fld qword ptr [esi+0*8*8]
+ fmul qword ptr [eax+0*8*8]
+ fld qword ptr [esi+1*8*8]
+ fmul qword ptr [eax+1*8*8]
+ fadd
+ fld qword ptr [esi+2*8*8]
+ fmul qword ptr [eax+2*8*8]
+ fadd
+ fld qword ptr [esi+3*8*8]
+ fmul qword ptr [eax+3*8*8]
+ fadd
+ fld qword ptr [esi+4*8*8]
+ fmul qword ptr [eax+4*8*8]
+ fadd
+ fld qword ptr [esi+5*8*8]
+ fmul qword ptr [eax+5*8*8]
+ fadd
+ fld qword ptr [esi+6*8*8]
+ fmul qword ptr [eax+6*8*8]
+ fadd
+ fld qword ptr [esi+7*8*8]
+ fmul qword ptr [eax+7*8*8]
+ fadd
+ fadd st(0), st(1)
+
+ fxch st(1)
+
+ fld qword ptr [esi+0*8*8]
+ fmul qword ptr [eax+0*8*8+8]
+ fld qword ptr [esi+1*8*8]
+ fmul qword ptr [eax+1*8*8+8]
+ fadd
+ fld qword ptr [esi+2*8*8]
+ fmul qword ptr [eax+2*8*8+8]
+ fadd
+ fld qword ptr [esi+3*8*8]
+ fmul qword ptr [eax+3*8*8+8]
+ fadd
+ fld qword ptr [esi+4*8*8]
+ fmul qword ptr [eax+4*8*8+8]
+ fadd
+ fld qword ptr [esi+5*8*8]
+ fmul qword ptr [eax+5*8*8+8]
+ fadd
+ fld qword ptr [esi+6*8*8]
+ fmul qword ptr [eax+6*8*8+8]
+ fadd
+ fld qword ptr [esi+7*8*8]
+ fmul qword ptr [eax+7*8*8+8]
+ fadd
+ fadd st(0), st(1)
+ add eax, 8*2
+
+ fxch st(2)
+ fstp qword ptr [edi]
+ fxch st(1)
+ fstp qword ptr [edi+8*8]
+ add edi, 8*8*2
+
+ dec ecx
+
+ jnz __col2
+ add eax, -8*8
+ add esi, +8
+ add edi, 8-8*8*8
+
+ sub ebx, 0x80000001
+ js __row2
+ //align 16
+ test ebx, ebx // align jump &| redo flags
+ jnz __row2
+ ffree st(0) // bye bye 0.5
+
+ // set x87 to floor mode
+ fstcw [fpold]
+ movzx eax, [fpold]
+
+ or eax, 0x0400 // round down - floor
+ mov [fpnew], ax
+ fldcw [fpnew]
+
+ // now floor the damn array
+ lea esi, [rnd]
+ mov edi, [block]
+ mov ebx, -256 // clip min
+ mov edx, +255 // clip max
+ mov ecx, 8
+ align 16
+ __floor:
+ fld qword ptr [esi+0*8]
+ fistp dword ptr [int0]
+ mov eax, [int0]
+ cmp eax, ebx
+ cmovl eax, ebx
+ cmp eax, edx
+ cmovg eax, edx
+ fld qword ptr [esi+1*8]
+ fistp dword ptr [int1]
+ mov word ptr [edi+0*2], ax
+ mov eax, [int1]
+ cmp eax, ebx
+ cmovl eax, ebx
+ cmp eax, edx
+ cmovg eax, edx
+ fld qword ptr [esi+2*8]
+ fistp dword ptr [int2]
+ mov word ptr [edi+1*2], ax
+ mov eax, [int2]
+ cmp eax, ebx
+ cmovl eax, ebx
+ cmp eax, edx
+ cmovg eax, edx
+ fld qword ptr [esi+3*8]
+ fistp dword ptr [int3]
+ mov word ptr [edi+2*2], ax
+ mov eax, [int3]
+ cmp eax, ebx
+ cmovl eax, ebx
+ cmp eax, edx
+ cmovg eax, edx
+ fld qword ptr [esi+4*8]
+ fistp dword ptr [int4]
+ mov word ptr [edi+3*2], ax
+ mov eax, [int4]
+ cmp eax, ebx
+ cmovl eax, ebx
+ cmp eax, edx
+ cmovg eax, edx
+ fld qword ptr [esi+5*8]
+ fistp dword ptr [int5]
+ mov word ptr [edi+4*2], ax
+ mov eax, [int5]
+ cmp eax, ebx
+ cmovl eax, ebx
+ cmp eax, edx
+ cmovg eax, edx
+ fld qword ptr [esi+6*8]
+ fistp dword ptr [int6]
+ mov word ptr [edi+5*2], ax
+ mov eax, [int6]
+ cmp eax, ebx
+ cmovl eax, ebx
+ cmp eax, edx
+ cmovg eax, edx
+ fld qword ptr [esi+7*8]
+ fistp dword ptr [int7]
+ mov word ptr [edi+6*2], ax
+ mov eax, [int7]
+ cmp eax, ebx
+ cmovl eax, ebx
+ cmp eax, edx
+ cmovg eax, edx
+ mov word ptr [edi+7*2], ax
+
+ add esi, 8*8
+ add edi, 8*2
+
+ sub ecx, 0x80000001
+ js __floor
+ //align 16
+ test ecx, ecx // align jump &| redo flags
+ jnz __floor
+
+ // set x87 to default mode
+ fldcw [fpold]
+ };
}
diff --git a/src/filters/source/D2VSource/resource.h b/src/filters/source/D2VSource/resource.h
index 1d1658441..98cb5e018 100644
--- a/src/filters/source/D2VSource/resource.h
+++ b/src/filters/source/D2VSource/resource.h
@@ -3,7 +3,7 @@
// Used by d2vsource.rc
// Next default values for new objects
-//
+//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
diff --git a/src/filters/source/DTSAC3Source/DTSAC3Source.cpp b/src/filters/source/DTSAC3Source/DTSAC3Source.cpp
index fc6251abf..ffa885fef 100644
--- a/src/filters/source/DTSAC3Source/DTSAC3Source.cpp
+++ b/src/filters/source/DTSAC3Source/DTSAC3Source.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
@@ -32,82 +32,82 @@
const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
{
- {&MEDIATYPE_Audio, &MEDIASUBTYPE_DTS},
- {&MEDIATYPE_DVD_ENCRYPTED_PACK, &MEDIASUBTYPE_DTS},
- {&MEDIATYPE_Audio, &MEDIASUBTYPE_DOLBY_AC3},
- {&MEDIATYPE_DVD_ENCRYPTED_PACK, &MEDIASUBTYPE_DOLBY_AC3},
+ {&MEDIATYPE_Audio, &MEDIASUBTYPE_DTS},
+ {&MEDIATYPE_DVD_ENCRYPTED_PACK, &MEDIASUBTYPE_DTS},
+ {&MEDIATYPE_Audio, &MEDIASUBTYPE_DOLBY_AC3},
+ {&MEDIATYPE_DVD_ENCRYPTED_PACK, &MEDIASUBTYPE_DOLBY_AC3},
};
const AMOVIESETUP_PIN sudOpPin[] =
{
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
const AMOVIESETUP_FILTER sudFilter[] =
{
#ifdef DDPLUS_ONLY
- {&__uuidof(CDTSAC3Source), L"MPC - DD+ Source", MERIT_NORMAL, countof(sudOpPin), sudOpPin}
+ {&__uuidof(CDTSAC3Source), L"MPC - DD+ Source", MERIT_NORMAL, countof(sudOpPin), sudOpPin}
#else
- {&__uuidof(CDTSAC3Source), L"MPC - DTS/AC3/DD+ Source", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
+ {&__uuidof(CDTSAC3Source), L"MPC - DTS/AC3/DD+ Source", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
#endif
};
CFactoryTemplate g_Templates[] =
{
- {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CDTSAC3Source>, NULL, &sudFilter[0]}
+ {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CDTSAC3Source>, NULL, &sudFilter[0]}
};
int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
- SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
- _T("0"), _T("0,4,,7FFE8001"));
+ SetRegKeyValue(
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
+ _T("0"), _T("0,4,,7FFE8001"));
- SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
- _T("1"), _T("0,2,,0B77"));
+ SetRegKeyValue(
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
+ _T("1"), _T("0,2,,0B77"));
- SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
- _T("2"), _T("0,2,,770B"));
+ SetRegKeyValue(
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
+ _T("2"), _T("0,2,,770B"));
- SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
- _T("Source Filter"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
+ SetRegKeyValue(
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
+ _T("Source Filter"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
#ifndef DDPLUS_ONLY
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".dts"),
- _T("Source Filter"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".dts"),
+ _T("Source Filter"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".ac3"),
- _T("Source Filter"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".ac3"),
+ _T("Source Filter"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
#endif
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".ddp"),
- _T("Source Filter"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".ddp"),
+ _T("Source Filter"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".ec3"),
- _T("Source Filter"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".ec3"),
+ _T("Source Filter"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
- return AMovieDllRegisterServer2(TRUE);
+ return AMovieDllRegisterServer2(TRUE);
}
STDAPI DllUnregisterServer()
{
- DeleteRegKey(_T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
+ DeleteRegKey(_T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
#ifndef DDPLUS_ONLY
- DeleteRegKey(_T("Media Type\\Extensions"), _T(".dts"));
- DeleteRegKey(_T("Media Type\\Extensions"), _T(".ac3"));
+ DeleteRegKey(_T("Media Type\\Extensions"), _T(".dts"));
+ DeleteRegKey(_T("Media Type\\Extensions"), _T(".ac3"));
#endif
- DeleteRegKey(_T("Media Type\\Extensions"), _T(".ddp"));
- DeleteRegKey(_T("Media Type\\Extensions"), _T(".ec3"));
+ DeleteRegKey(_T("Media Type\\Extensions"), _T(".ddp"));
+ DeleteRegKey(_T("Media Type\\Extensions"), _T(".ec3"));
- return AMovieDllRegisterServer2(FALSE);
+ return AMovieDllRegisterServer2(FALSE);
}
#include "../../FilterApp.h"
@@ -121,7 +121,7 @@ CFilterApp theApp;
//
CDTSAC3Source::CDTSAC3Source(LPUNKNOWN lpunk, HRESULT* phr)
- : CBaseSource<CDTSAC3Stream>(NAME("CDTSAC3Source"), lpunk, phr, __uuidof(this))
+ : CBaseSource<CDTSAC3Stream>(NAME("CDTSAC3Source"), lpunk, phr, __uuidof(this))
{
}
@@ -131,165 +131,165 @@ CDTSAC3Source::~CDTSAC3Source()
// CDTSAC3Stream
-CDTSAC3Stream::CDTSAC3Stream(const WCHAR* wfn, CSource* pParent, HRESULT* phr)
- : CBaseStream(NAME("CDTSAC3Stream"), pParent, phr)
- , m_nFileOffset(0)
+CDTSAC3Stream::CDTSAC3Stream(const WCHAR* wfn, CSource* pParent, HRESULT* phr)
+ : CBaseStream(NAME("CDTSAC3Stream"), pParent, phr)
+ , m_nFileOffset(0)
{
- CAutoLock cAutoLock(&m_cSharedState);
-
- m_subtype = GUID_NULL;
- m_wFormatTag = 0;
- m_streamid = 0;
-
- CString fn(wfn);
-
- if(!m_file.Open(fn, CFile::modeRead|CFile::shareDenyNone))
- {
- if(phr) *phr = E_FAIL;
- return;
- }
-
- DWORD id = 0;
- if(m_file.Read(&id, sizeof(id)) != sizeof(id)
- || id != 0x0180FE7F && (WORD)id != 0x0b77 && (WORD)id != 0x770b)
- {
- if(phr) *phr = E_FAIL;
- return;
- }
-
- if(id == 0x0180FE7F)
- {
+ CAutoLock cAutoLock(&m_cSharedState);
+
+ m_subtype = GUID_NULL;
+ m_wFormatTag = 0;
+ m_streamid = 0;
+
+ CString fn(wfn);
+
+ if(!m_file.Open(fn, CFile::modeRead | CFile::shareDenyNone))
+ {
+ if(phr) *phr = E_FAIL;
+ return;
+ }
+
+ DWORD id = 0;
+ if(m_file.Read(&id, sizeof(id)) != sizeof(id)
+ || id != 0x0180FE7F && (WORD)id != 0x0b77 && (WORD)id != 0x770b)
+ {
+ if(phr) *phr = E_FAIL;
+ return;
+ }
+
+ if(id == 0x0180FE7F)
+ {
#ifdef DDPLUS_ONLY
-//Temporary patch to disable DTS source
- if(phr) *phr = E_FAIL;
- return;
+//Temporary patch to disable DTS source
+ if(phr) *phr = E_FAIL;
+ return;
#endif
- BYTE buff[8];
- m_file.Read(buff, 8);
-
- int frametype = (buff[0]>>7); // 1
- int deficitsamplecount = (buff[0]>>2)&31; // 5
- int crcpresent = (buff[0]>>1)&1; // 1
- int npcmsampleblocks = ((buff[0]&1)<<6)|(buff[1]>>2); // 7
- int framebytes = (((buff[1]&3)<<12)|(buff[2]<<4)|(buff[3]>>4)) + 1; // 14
- int audiochannelarrangement = (buff[3]&15)<<2|(buff[4]>>6); // 6
- int freq = (buff[4]>>2)&15; // 4
- int transbitrate = ((buff[4]&3)<<3)|(buff[5]>>5); // 5
-
- int freqtbl[] =
- {
- 0,8000,16000,32000,
- 0,0,
- 11025,22050,44100,
- 0,0,
- 12000,24000,48000,
- 0,0
- };
-
- int bitratetbl[] =
- {
- 32000,56000,64000,96000,112000,128000,192000,224000,
- 256000,320000,384000,448000,512000,576000,640000,754500,
- 960000,1024000,1152000,1280000,1344000,1408000,1411200,1472000,
- 1509750,1920000,2048000,3072000,3840000,0,0,0
- };
+ BYTE buff[8];
+ m_file.Read(buff, 8);
+
+ int frametype = (buff[0] >> 7); // 1
+ int deficitsamplecount = (buff[0] >> 2) & 31; // 5
+ int crcpresent = (buff[0] >> 1) & 1; // 1
+ int npcmsampleblocks = ((buff[0] & 1) << 6) | (buff[1] >> 2); // 7
+ int framebytes = (((buff[1] & 3) << 12) | (buff[2] << 4) | (buff[3] >> 4)) + 1; // 14
+ int audiochannelarrangement = (buff[3] & 15) << 2 | (buff[4] >> 6); // 6
+ int freq = (buff[4] >> 2) & 15; // 4
+ int transbitrate = ((buff[4] & 3) << 3) | (buff[5] >> 5); // 5
+
+ int freqtbl[] =
+ {
+ 0, 8000, 16000, 32000,
+ 0, 0,
+ 11025, 22050, 44100,
+ 0, 0,
+ 12000, 24000, 48000,
+ 0, 0
+ };
+
+ int bitratetbl[] =
+ {
+ 32000, 56000, 64000, 96000, 112000, 128000, 192000, 224000,
+ 256000, 320000, 384000, 448000, 512000, 576000, 640000, 754500,
+ 960000, 1024000, 1152000, 1280000, 1344000, 1408000, 1411200, 1472000,
+ 1509750, 1920000, 2048000, 3072000, 3840000, 0, 0, 0
+ };
#define DTS_MAGIC_NUMBER 6 //magic number to make sonic audio decoder 4.2 happy
- m_nSamplesPerSec = freqtbl[freq];
- m_nAvgBytesPerSec = (bitratetbl[transbitrate] + 4) / 8;
+ m_nSamplesPerSec = freqtbl[freq];
+ m_nAvgBytesPerSec = (bitratetbl[transbitrate] + 4) / 8;
// m_nBytesPerFrame = m_nAvgBytesPerSec*10.656063618290258449304174950298/1000 + 0.5;
- m_nBytesPerFrame = framebytes*DTS_MAGIC_NUMBER;
- if (framebytes == 2012)
- {
- // DTS and DTS-HD tracks from HD DVD and Blu-Ray sources have framesizes of 2012 bytes
- // but if we handle them mathematically "correctly", audio sync will slowly drift away
- // we have to handle them as if they had 2013 bytes
- m_AvgTimePerFrame = 10000000i64 * (2013*DTS_MAGIC_NUMBER) * 8 / bitratetbl[transbitrate];
- }
- else
- m_AvgTimePerFrame = 10000000i64 * m_nBytesPerFrame * 8 / bitratetbl[transbitrate];
-
- m_subtype = MEDIASUBTYPE_DTS;
- m_wFormatTag = WAVE_FORMAT_DVD_DTS;
- m_streamid = 0x88;
- }
- else
- {
- BYTE info, info1, bsid;
- if((BYTE)id == 0x77) m_file.Seek(1, CFile::current); // LE
- m_file.Read(&info, 1);
- m_file.Read(&info1, 1);
- bsid = (info1>>3);
-
- if(bsid>=0 && bsid<=8) //AC3
- {
+ m_nBytesPerFrame = framebytes * DTS_MAGIC_NUMBER;
+ if(framebytes == 2012)
+ {
+ // DTS and DTS-HD tracks from HD DVD and Blu-Ray sources have framesizes of 2012 bytes
+ // but if we handle them mathematically "correctly", audio sync will slowly drift away
+ // we have to handle them as if they had 2013 bytes
+ m_AvgTimePerFrame = 10000000i64 * (2013 * DTS_MAGIC_NUMBER) * 8 / bitratetbl[transbitrate];
+ }
+ else
+ m_AvgTimePerFrame = 10000000i64 * m_nBytesPerFrame * 8 / bitratetbl[transbitrate];
+
+ m_subtype = MEDIASUBTYPE_DTS;
+ m_wFormatTag = WAVE_FORMAT_DVD_DTS;
+ m_streamid = 0x88;
+ }
+ else
+ {
+ BYTE info, info1, bsid;
+ if((BYTE)id == 0x77) m_file.Seek(1, CFile::current); // LE
+ m_file.Read(&info, 1);
+ m_file.Read(&info1, 1);
+ bsid = (info1 >> 3);
+
+ if(bsid >= 0 && bsid <= 8) //AC3
+ {
#ifdef DDPLUS_ONLY
-//Temporary patch to disable AC3 source
- if(phr) *phr = E_FAIL;
- return;
+//Temporary patch to disable AC3 source
+ if(phr) *phr = E_FAIL;
+ return;
#endif
- BYTE freq = info>>6;
- BYTE bitrate = info&0x3f;
+ BYTE freq = info >> 6;
+ BYTE bitrate = info & 0x3f;
- if(bitrate >= 38)
- {
- if(phr) *phr = E_FAIL;
- return;
- }
+ if(bitrate >= 38)
+ {
+ if(phr) *phr = E_FAIL;
+ return;
+ }
- int freqtbl[] = {48000,44100,32000,48000};
+ int freqtbl[] = {48000, 44100, 32000, 48000};
- int bitratetbl[] =
- {
- 32000,32000,40000,40000,48000,48000,56000,56000,64000,64000,
- 80000,80000,96000,96000,112000,112000,128000,128000,160000,160000,
- 192000,192000,224000,224000,256000,256000,320000,320000,384000,384000,
- 448000,448000,512000,512000,576000,576000,640000,640000
- };
+ int bitratetbl[] =
+ {
+ 32000, 32000, 40000, 40000, 48000, 48000, 56000, 56000, 64000, 64000,
+ 80000, 80000, 96000, 96000, 112000, 112000, 128000, 128000, 160000, 160000,
+ 192000, 192000, 224000, 224000, 256000, 256000, 320000, 320000, 384000, 384000,
+ 448000, 448000, 512000, 512000, 576000, 576000, 640000, 640000
+ };
#define AC3_MAGIC_NUMBER 3 //magic number to make sonic audio decoder 4.2 happy
- m_nSamplesPerSec = freqtbl[freq];
- m_nAvgBytesPerSec = (bitratetbl[bitrate] + 4) / 8;
- m_nBytesPerFrame = m_nAvgBytesPerSec*32/1000*AC3_MAGIC_NUMBER;
- m_AvgTimePerFrame = 10000000i64 * m_nBytesPerFrame * 8 / bitratetbl[bitrate];
-
- m_subtype = MEDIASUBTYPE_DOLBY_AC3;
- m_wFormatTag = WAVE_FORMAT_DOLBY_AC3;
- m_streamid = 0x80;
-
- }
- else if(bsid>=11 && bsid <=16) //DD+
- {
- BYTE fscod = info>>6;
- BYTE numblkscod = (info&0x30)>>4;
- if(fscod == 3)
- {
- fscod = numblkscod+3;
- numblkscod = 3;
- }
-
- int freqtbl[] = {48000,44100,32000,22400,22050,16000,48000};
- m_nSamplesPerSec = freqtbl[fscod];
- m_nBytesPerFrame = (2+(id >> 23)+((id&0x00070000)>>7))*6;
- int timetbl[] = {320000, 640000, 960000, 1920000};
- m_AvgTimePerFrame = timetbl[numblkscod];
-
- m_subtype = MEDIASUBTYPE_DOLBY_AC3;
- m_wFormatTag = WAVE_FORMAT_DOLBY_AC3;
- m_streamid = 0xC0;
- }
- else
- {
- if(phr) *phr = E_FAIL;
- return;
- }
-
- }
-
- m_rtDuration = m_AvgTimePerFrame * m_file.GetLength() / m_nBytesPerFrame;
- m_rtStop = m_rtDuration;
+ m_nSamplesPerSec = freqtbl[freq];
+ m_nAvgBytesPerSec = (bitratetbl[bitrate] + 4) / 8;
+ m_nBytesPerFrame = m_nAvgBytesPerSec * 32 / 1000 * AC3_MAGIC_NUMBER;
+ m_AvgTimePerFrame = 10000000i64 * m_nBytesPerFrame * 8 / bitratetbl[bitrate];
+
+ m_subtype = MEDIASUBTYPE_DOLBY_AC3;
+ m_wFormatTag = WAVE_FORMAT_DOLBY_AC3;
+ m_streamid = 0x80;
+
+ }
+ else if(bsid >= 11 && bsid <= 16) //DD+
+ {
+ BYTE fscod = info >> 6;
+ BYTE numblkscod = (info & 0x30) >> 4;
+ if(fscod == 3)
+ {
+ fscod = numblkscod + 3;
+ numblkscod = 3;
+ }
+
+ int freqtbl[] = {48000, 44100, 32000, 22400, 22050, 16000, 48000};
+ m_nSamplesPerSec = freqtbl[fscod];
+ m_nBytesPerFrame = (2 + (id >> 23) + ((id & 0x00070000) >> 7)) * 6;
+ int timetbl[] = {320000, 640000, 960000, 1920000};
+ m_AvgTimePerFrame = timetbl[numblkscod];
+
+ m_subtype = MEDIASUBTYPE_DOLBY_AC3;
+ m_wFormatTag = WAVE_FORMAT_DOLBY_AC3;
+ m_streamid = 0xC0;
+ }
+ else
+ {
+ if(phr) *phr = E_FAIL;
+ return;
+ }
+
+ }
+
+ m_rtDuration = m_AvgTimePerFrame * m_file.GetLength() / m_nBytesPerFrame;
+ m_rtStop = m_rtDuration;
}
CDTSAC3Stream::~CDTSAC3Stream()
@@ -303,8 +303,8 @@ HRESULT CDTSAC3Stream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERT
HRESULT hr = NOERROR;
- pProperties->cBuffers = 1;
- pProperties->cbBuffer = m_nBytesPerFrame+35;
+ pProperties->cBuffers = 1;
+ pProperties->cbBuffer = m_nBytesPerFrame + 35;
ALLOCATOR_PROPERTIES Actual;
if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
@@ -317,157 +317,157 @@ HRESULT CDTSAC3Stream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERT
HRESULT CDTSAC3Stream::FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len)
{
- BYTE* pOutOrg = pOut;
-
- const GUID* majortype = &m_mt.majortype;
- const GUID* subtype = &m_mt.subtype;
-
- if(*majortype == MEDIATYPE_DVD_ENCRYPTED_PACK)
- {
- BYTE PESHeader[] =
- {
- 0x00,0x00,0x01,0xBA, // PES id
- 0x44,0x00,0x04,0x00,0x04,0x01, // SCR (0)
- 0x01,0x89,0xC3,0xF8, // mux rate (1260000 bytes/sec, 22bits), marker (2bits), reserved (~0, 5bits), stuffing (0, 3bits)
- };
-
- memcpy(pOut, &PESHeader, sizeof(PESHeader));
- pOut += sizeof(PESHeader);
-
- majortype = &MEDIATYPE_MPEG2_PES;
- }
-
- if(*majortype == MEDIATYPE_MPEG2_PES)
- {
- BYTE Private1Header[] =
- {
- 0x00,0x00,0x01,0xBD, // private stream 1 id
- (m_nBytesPerFrame+15)>>8,(m_nBytesPerFrame+15)&255, // packet length
- 0x81,0x80, // marker, original, PTS - flags
- 0x08, // packet data starting offset
- 0x21,0x00,0x01,0x00,0x01, // PTS (0)
- 0xFF,0xFF,0xFF, // stuffing
- m_streamid, // stream id (0)
- 0x01,0x00,0x01, // no idea about this (might be the current sector on the disc), but dvd2avi doesn't output it to the ac3/dts file so we have to put it back
- };
-
- memcpy(pOut, &Private1Header, sizeof(Private1Header));
- pOut += sizeof(Private1Header);
-
- majortype = &MEDIATYPE_Audio;
- }
-
- if(*majortype == MEDIATYPE_Audio)
- {
- m_file.Seek(m_nFileOffset + nFrame*m_nBytesPerFrame, CFile::begin);
- if(m_file.Read(pOut, m_nBytesPerFrame) < m_nBytesPerFrame) return S_FALSE;
- pOut += m_nBytesPerFrame;
- }
-
- len = pOut - pOutOrg;
-
- return S_OK;
+ BYTE* pOutOrg = pOut;
+
+ const GUID* majortype = &m_mt.majortype;
+ const GUID* subtype = &m_mt.subtype;
+
+ if(*majortype == MEDIATYPE_DVD_ENCRYPTED_PACK)
+ {
+ BYTE PESHeader[] =
+ {
+ 0x00, 0x00, 0x01, 0xBA, // PES id
+ 0x44, 0x00, 0x04, 0x00, 0x04, 0x01, // SCR (0)
+ 0x01, 0x89, 0xC3, 0xF8, // mux rate (1260000 bytes/sec, 22bits), marker (2bits), reserved (~0, 5bits), stuffing (0, 3bits)
+ };
+
+ memcpy(pOut, &PESHeader, sizeof(PESHeader));
+ pOut += sizeof(PESHeader);
+
+ majortype = &MEDIATYPE_MPEG2_PES;
+ }
+
+ if(*majortype == MEDIATYPE_MPEG2_PES)
+ {
+ BYTE Private1Header[] =
+ {
+ 0x00, 0x00, 0x01, 0xBD, // private stream 1 id
+ (m_nBytesPerFrame + 15) >> 8, (m_nBytesPerFrame + 15) & 255, // packet length
+ 0x81, 0x80, // marker, original, PTS - flags
+ 0x08, // packet data starting offset
+ 0x21, 0x00, 0x01, 0x00, 0x01, // PTS (0)
+ 0xFF, 0xFF, 0xFF, // stuffing
+ m_streamid, // stream id (0)
+ 0x01, 0x00, 0x01, // no idea about this (might be the current sector on the disc), but dvd2avi doesn't output it to the ac3/dts file so we have to put it back
+ };
+
+ memcpy(pOut, &Private1Header, sizeof(Private1Header));
+ pOut += sizeof(Private1Header);
+
+ majortype = &MEDIATYPE_Audio;
+ }
+
+ if(*majortype == MEDIATYPE_Audio)
+ {
+ m_file.Seek(m_nFileOffset + nFrame * m_nBytesPerFrame, CFile::begin);
+ if(m_file.Read(pOut, m_nBytesPerFrame) < m_nBytesPerFrame) return S_FALSE;
+ pOut += m_nBytesPerFrame;
+ }
+
+ len = pOut - pOutOrg;
+
+ return S_OK;
}
bool CDTSAC3Stream::CheckDTS(const CMediaType* pmt)
{
- return (pmt->majortype == MEDIATYPE_Audio
- || pmt->majortype == MEDIATYPE_MPEG2_PES
- || pmt->majortype == MEDIATYPE_DVD_ENCRYPTED_PACK)
- && pmt->subtype == MEDIASUBTYPE_DTS;
+ return (pmt->majortype == MEDIATYPE_Audio
+ || pmt->majortype == MEDIATYPE_MPEG2_PES
+ || pmt->majortype == MEDIATYPE_DVD_ENCRYPTED_PACK)
+ && pmt->subtype == MEDIASUBTYPE_DTS;
// return pmt->majortype == MEDIATYPE_Audio && pmt->subtype == MEDIASUBTYPE_DTS;
}
bool CDTSAC3Stream::CheckWAVEDTS(const CMediaType* pmt)
{
- return pmt->majortype == MEDIATYPE_Audio
- && pmt->subtype == MEDIASUBTYPE_WAVE_DTS
- && pmt->formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_DVD_DTS;
+ return pmt->majortype == MEDIATYPE_Audio
+ && pmt->subtype == MEDIASUBTYPE_WAVE_DTS
+ && pmt->formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_DVD_DTS;
}
bool CDTSAC3Stream::CheckAC3(const CMediaType* pmt)
{
- return (pmt->majortype == MEDIATYPE_Audio
- || pmt->majortype == MEDIATYPE_MPEG2_PES
- || pmt->majortype == MEDIATYPE_DVD_ENCRYPTED_PACK)
- && pmt->subtype == MEDIASUBTYPE_DOLBY_AC3;
+ return (pmt->majortype == MEDIATYPE_Audio
+ || pmt->majortype == MEDIATYPE_MPEG2_PES
+ || pmt->majortype == MEDIATYPE_DVD_ENCRYPTED_PACK)
+ && pmt->subtype == MEDIASUBTYPE_DOLBY_AC3;
// return pmt->majortype == MEDIATYPE_Audio && pmt->subtype == MEDIASUBTYPE_DOLBY_AC3;
}
bool CDTSAC3Stream::CheckWAVEAC3(const CMediaType* pmt)
{
- return pmt->majortype == MEDIATYPE_Audio
- && pmt->subtype == MEDIASUBTYPE_DOLBY_AC3
- && pmt->formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_DOLBY_AC3;
+ return pmt->majortype == MEDIATYPE_Audio
+ && pmt->subtype == MEDIASUBTYPE_DOLBY_AC3
+ && pmt->formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_DOLBY_AC3;
}
HRESULT CDTSAC3Stream::GetMediaType(int iPosition, CMediaType* pmt)
{
CAutoLock cAutoLock(m_pFilter->pStateLock());
- if(iPosition >= 0 && iPosition < 5)
- {
- pmt->subtype = m_subtype;
- pmt->formattype = FORMAT_WaveFormatEx;
- WAVEFORMATEX* wfe = (WAVEFORMATEX*)pmt->AllocFormatBuffer(sizeof(WAVEFORMATEX));
- memset(wfe, 0, sizeof(WAVEFORMATEX));
- wfe->cbSize = sizeof(WAVEFORMATEX);
- wfe->wFormatTag = WAVE_FORMAT_PCM;
- wfe->nSamplesPerSec = m_nSamplesPerSec;
- wfe->nAvgBytesPerSec = m_nAvgBytesPerSec;
- wfe->nChannels = 6;
-
- switch(iPosition)
- {
- case 0:
- pmt->majortype = MEDIATYPE_Audio;
- break;
- case 1:
- pmt->ResetFormatBuffer();
- pmt->formattype = FORMAT_None;
- case 2:
- pmt->majortype = MEDIATYPE_MPEG2_PES;
- break;
- case 3:
- pmt->ResetFormatBuffer();
- pmt->formattype = FORMAT_None;
- case 4:
- pmt->majortype = MEDIATYPE_DVD_ENCRYPTED_PACK;
- break;
- default:
- return E_INVALIDARG;
- }
- }
- else if(iPosition == 5)
- {
- pmt->majortype = MEDIATYPE_Audio;
- pmt->subtype = FOURCCMap(m_wFormatTag);
- pmt->formattype = FORMAT_WaveFormatEx;
- WAVEFORMATEX* wfe = (WAVEFORMATEX*)pmt->AllocFormatBuffer(sizeof(WAVEFORMATEX));
- memset(wfe, 0, sizeof(WAVEFORMATEX));
- wfe->cbSize = sizeof(WAVEFORMATEX);
- wfe->wFormatTag = m_wFormatTag;
- wfe->nSamplesPerSec = m_nSamplesPerSec;
- wfe->nAvgBytesPerSec = m_nAvgBytesPerSec;
- wfe->nChannels = 2;
- wfe->nBlockAlign = 1;
- }
- else
- {
- return VFW_S_NO_MORE_ITEMS;
- }
+ if(iPosition >= 0 && iPosition < 5)
+ {
+ pmt->subtype = m_subtype;
+ pmt->formattype = FORMAT_WaveFormatEx;
+ WAVEFORMATEX* wfe = (WAVEFORMATEX*)pmt->AllocFormatBuffer(sizeof(WAVEFORMATEX));
+ memset(wfe, 0, sizeof(WAVEFORMATEX));
+ wfe->cbSize = sizeof(WAVEFORMATEX);
+ wfe->wFormatTag = WAVE_FORMAT_PCM;
+ wfe->nSamplesPerSec = m_nSamplesPerSec;
+ wfe->nAvgBytesPerSec = m_nAvgBytesPerSec;
+ wfe->nChannels = 6;
+
+ switch(iPosition)
+ {
+ case 0:
+ pmt->majortype = MEDIATYPE_Audio;
+ break;
+ case 1:
+ pmt->ResetFormatBuffer();
+ pmt->formattype = FORMAT_None;
+ case 2:
+ pmt->majortype = MEDIATYPE_MPEG2_PES;
+ break;
+ case 3:
+ pmt->ResetFormatBuffer();
+ pmt->formattype = FORMAT_None;
+ case 4:
+ pmt->majortype = MEDIATYPE_DVD_ENCRYPTED_PACK;
+ break;
+ default:
+ return E_INVALIDARG;
+ }
+ }
+ else if(iPosition == 5)
+ {
+ pmt->majortype = MEDIATYPE_Audio;
+ pmt->subtype = FOURCCMap(m_wFormatTag);
+ pmt->formattype = FORMAT_WaveFormatEx;
+ WAVEFORMATEX* wfe = (WAVEFORMATEX*)pmt->AllocFormatBuffer(sizeof(WAVEFORMATEX));
+ memset(wfe, 0, sizeof(WAVEFORMATEX));
+ wfe->cbSize = sizeof(WAVEFORMATEX);
+ wfe->wFormatTag = m_wFormatTag;
+ wfe->nSamplesPerSec = m_nSamplesPerSec;
+ wfe->nAvgBytesPerSec = m_nAvgBytesPerSec;
+ wfe->nChannels = 2;
+ wfe->nBlockAlign = 1;
+ }
+ else
+ {
+ return VFW_S_NO_MORE_ITEMS;
+ }
pmt->SetTemporalCompression(FALSE);
- return S_OK;
+ return S_OK;
}
HRESULT CDTSAC3Stream::CheckMediaType(const CMediaType* pmt)
{
- return CheckDTS(pmt) || CheckWAVEDTS(pmt)
- || CheckAC3(pmt) || CheckWAVEAC3(pmt)
- ? S_OK
- : E_INVALIDARG;
+ return CheckDTS(pmt) || CheckWAVEDTS(pmt)
+ || CheckAC3(pmt) || CheckWAVEAC3(pmt)
+ ? S_OK
+ : E_INVALIDARG;
}
diff --git a/src/filters/source/DTSAC3Source/DTSAC3Source.h b/src/filters/source/DTSAC3Source/DTSAC3Source.h
index 6c9a30140..4022d58db 100644
--- a/src/filters/source/DTSAC3Source/DTSAC3Source.h
+++ b/src/filters/source/DTSAC3Source/DTSAC3Source.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
@@ -30,30 +30,30 @@ class CDTSAC3Stream;
class CDTSAC3Source : public CBaseSource<CDTSAC3Stream>
{
public:
- CDTSAC3Source(LPUNKNOWN lpunk, HRESULT* phr);
- virtual ~CDTSAC3Source();
+ CDTSAC3Source(LPUNKNOWN lpunk, HRESULT* phr);
+ virtual ~CDTSAC3Source();
};
class CDTSAC3Stream : public CBaseStream
{
- CFile m_file;
- int m_nFileOffset, m_nBytesPerFrame, m_nAvgBytesPerSec, m_nSamplesPerSec;
- GUID m_subtype;
- WORD m_wFormatTag;
- BYTE m_streamid;
+ CFile m_file;
+ int m_nFileOffset, m_nBytesPerFrame, m_nAvgBytesPerSec, m_nSamplesPerSec;
+ GUID m_subtype;
+ WORD m_wFormatTag;
+ BYTE m_streamid;
- bool CheckDTS(const CMediaType* pmt);
- bool CheckWAVEDTS(const CMediaType* pmt);
- bool CheckAC3(const CMediaType* pmt);
- bool CheckWAVEAC3(const CMediaType* pmt);
+ bool CheckDTS(const CMediaType* pmt);
+ bool CheckWAVEDTS(const CMediaType* pmt);
+ bool CheckAC3(const CMediaType* pmt);
+ bool CheckWAVEAC3(const CMediaType* pmt);
public:
CDTSAC3Stream(const WCHAR* wfn, CSource* pParent, HRESULT* phr);
- virtual ~CDTSAC3Stream();
+ virtual ~CDTSAC3Stream();
HRESULT FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len);
-
- HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
+
+ HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
HRESULT CheckMediaType(const CMediaType* pMediaType);
HRESULT GetMediaType(int iPosition, CMediaType* pmt);
};
diff --git a/src/filters/source/DTSAC3Source/resource.h b/src/filters/source/DTSAC3Source/resource.h
index 3507c6e74..6e541c0c4 100644
--- a/src/filters/source/DTSAC3Source/resource.h
+++ b/src/filters/source/DTSAC3Source/resource.h
@@ -3,7 +3,7 @@
// Used by dtsac3source.rc
// Next default values for new objects
-//
+//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
diff --git a/src/filters/source/DTSAC3Source/stdafx.cpp b/src/filters/source/DTSAC3Source/stdafx.cpp
index 396f14d73..4b148b3b2 100644
--- a/src/filters/source/DTSAC3Source/stdafx.cpp
+++ b/src/filters/source/DTSAC3Source/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
diff --git a/src/filters/source/DTSAC3Source/stdafx.h b/src/filters/source/DTSAC3Source/stdafx.h
index c35359c38..a9f666228 100644
--- a/src/filters/source/DTSAC3Source/stdafx.h
+++ b/src/filters/source/DTSAC3Source/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
diff --git a/src/filters/source/FLICSource/FLICSource.cpp b/src/filters/source/FLICSource/FLICSource.cpp
index 1c291cd33..1d892df6f 100644
--- a/src/filters/source/FLICSource/FLICSource.cpp
+++ b/src/filters/source/FLICSource/FLICSource.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
@@ -27,58 +27,58 @@
const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
{
- {&MEDIATYPE_Video, &MEDIASUBTYPE_RGB32},
+ {&MEDIATYPE_Video, &MEDIASUBTYPE_RGB32},
};
const AMOVIESETUP_PIN sudOpPin[] =
{
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
const AMOVIESETUP_FILTER sudFilter[] =
{
- {&__uuidof(CFLICSource), L"MPC - FLICSource", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
+ {&__uuidof(CFLICSource), L"MPC - FLICSource", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
};
CFactoryTemplate g_Templates[] =
{
- {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CFLICSource>, NULL, &sudFilter[0]}
+ {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CFLICSource>, NULL, &sudFilter[0]}
};
int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
- SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"),
- _T("0"), _T("4,2,,11AF"));
+ SetRegKeyValue(
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"),
+ _T("0"), _T("4,2,,11AF"));
- SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"),
- _T("1"), _T("4,2,,12AF"));
+ SetRegKeyValue(
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"),
+ _T("1"), _T("4,2,,12AF"));
- SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"),
- _T("Source Filter"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"));
+ SetRegKeyValue(
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"),
+ _T("Source Filter"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"));
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".fli"),
- _T("Source Filter"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"));
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".fli"),
+ _T("Source Filter"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"));
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".flc"),
- _T("Source Filter"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"));
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".flc"),
+ _T("Source Filter"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"));
- return AMovieDllRegisterServer2(TRUE);
+ return AMovieDllRegisterServer2(TRUE);
}
STDAPI DllUnregisterServer()
{
- DeleteRegKey(_T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"));
- DeleteRegKey(_T("Media Type\\Extensions"), _T(".fli"));
- DeleteRegKey(_T("Media Type\\Extensions"), _T(".flc"));
+ DeleteRegKey(_T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"));
+ DeleteRegKey(_T("Media Type\\Extensions"), _T(".fli"));
+ DeleteRegKey(_T("Media Type\\Extensions"), _T(".flc"));
- return AMovieDllRegisterServer2(FALSE);
+ return AMovieDllRegisterServer2(FALSE);
}
#include "../../FilterApp.h"
@@ -92,7 +92,7 @@ CFilterApp theApp;
//
CFLICSource::CFLICSource(LPUNKNOWN lpunk, HRESULT* phr)
- : CSource(NAME("CFLICSource"), lpunk, __uuidof(this))
+ : CSource(NAME("CFLICSource"), lpunk, __uuidof(this))
{
}
@@ -104,205 +104,205 @@ STDMETHODIMP CFLICSource::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
CheckPointer(ppv, E_POINTER);
- return
- QI(IFileSourceFilter)
- QI(IAMFilterMiscFlags)
- __super::NonDelegatingQueryInterface(riid, ppv);
+ return
+ QI(IFileSourceFilter)
+ QI(IAMFilterMiscFlags)
+ __super::NonDelegatingQueryInterface(riid, ppv);
}
// IFileSourceFilter
-STDMETHODIMP CFLICSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
+STDMETHODIMP CFLICSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
{
- if(GetPinCount() > 0)
- return VFW_E_ALREADY_CONNECTED;
+ if(GetPinCount() > 0)
+ return VFW_E_ALREADY_CONNECTED;
- HRESULT hr = S_OK;
- if(!(DNew CFLICStream(pszFileName, this, &hr)))
- return E_OUTOFMEMORY;
+ HRESULT hr = S_OK;
+ if(!(DNew CFLICStream(pszFileName, this, &hr)))
+ return E_OUTOFMEMORY;
- if(FAILED(hr))
- return hr;
+ if(FAILED(hr))
+ return hr;
- m_fn = pszFileName;
+ m_fn = pszFileName;
- return S_OK;
+ return S_OK;
}
STDMETHODIMP CFLICSource::GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
{
- if(!ppszFileName) return E_POINTER;
-
- if(!(*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength()+1)*sizeof(WCHAR))))
- return E_OUTOFMEMORY;
+ if(!ppszFileName) return E_POINTER;
+
+ if(!(*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength() + 1) * sizeof(WCHAR))))
+ return E_OUTOFMEMORY;
- wcscpy(*ppszFileName, m_fn);
+ wcscpy(*ppszFileName, m_fn);
- return S_OK;
+ return S_OK;
}
// IAMFilterMiscFlags
ULONG CFLICSource::GetMiscFlags()
{
- return AM_FILTER_MISC_FLAGS_IS_SOURCE;
+ return AM_FILTER_MISC_FLAGS_IS_SOURCE;
}
// CFLICStream
-CFLICStream::CFLICStream(const WCHAR* wfn, CFLICSource* pParent, HRESULT* phr)
- : CSourceStream(NAME("FLICStream"), phr, pParent, L"Output")
- , CSourceSeeking(NAME("FLICStream"), (IPin*)this, phr, &m_cSharedState)
- , m_bDiscontinuity(FALSE), m_bFlushing(FALSE)
-{
- CAutoLock cAutoLock(&m_cSharedState);
-
- CString fn(wfn);
-
- if(!m_flic.Open(fn, CFile::modeRead|CFile::shareDenyNone))
- {
- if(phr) *phr = E_FAIL;
- return;
- }
-
- if(m_flic.Read(&m_hdr, sizeof(m_hdr)) != sizeof(m_hdr)
- || (m_hdr.id != 0xaf11 && m_hdr.id != 0xaf12)
- || m_hdr.bpp != 8)
- {
- if(phr) *phr = E_FAIL;
- return;
- }
-
- m_AvgTimePerFrame = (m_hdr.id == 0xaf11)
- ? 10000000i64 * max(m_hdr.ticks, 1) / 70
- : 10000000i64 * max(m_hdr.ticks, 1) / 1000;
-
- // not tested (lack of test files)
- {
- __int64 pos = m_flic.GetPosition();
- FLIC_PREFIX fp;
- if(m_flic.Read(&fp, sizeof(fp)) != sizeof(fp) || fp.id != 0xf100)
- m_flic.Seek(pos, CFile::begin);
- else
- m_flic.Seek(pos + fp.size, CFile::begin);
- }
-
- do
- {
- FLIC_FRAME_ENTRY ffe;
- if(m_flic.Read(&ffe.hdr, sizeof(ffe.hdr)) != sizeof(ffe.hdr) || ffe.hdr.id != 0xf1fa)
- break;
- ffe.pos = m_flic.GetPosition();
- ffe.fKeyframe = (m_frames.GetCount() == 0);
-
- int chunk = 0;
- while(chunk < ffe.hdr.chunks)
- {
- FLIC_CHUNK fc;
- if(m_flic.Read(&fc, sizeof(fc)) != sizeof(fc))
- break;
-/*
- switch(fc.type)
- {
- case FLIC_COLOR: _colorchunk(); break;
- case FLIC_256_COLOR: _color256chunk(); break;
- case FLIC_BRUN: _brunchunk(); break;
- case FLIC_LC: _lcchunk(); break;
- case FLIC_DELTA: _deltachunk(); break;
- case FLIC_BLACK: _blackchunk(); break;
- case FLIC_COPY: _copychunk(); break;
- case FLIC_MINI: break;
- default: break;
- }
-*/
- ffe.fKeyframe =
- (/*fc.type == FLIC_256_COLOR
+CFLICStream::CFLICStream(const WCHAR* wfn, CFLICSource* pParent, HRESULT* phr)
+ : CSourceStream(NAME("FLICStream"), phr, pParent, L"Output")
+ , CSourceSeeking(NAME("FLICStream"), (IPin*)this, phr, &m_cSharedState)
+ , m_bDiscontinuity(FALSE), m_bFlushing(FALSE)
+{
+ CAutoLock cAutoLock(&m_cSharedState);
+
+ CString fn(wfn);
+
+ if(!m_flic.Open(fn, CFile::modeRead | CFile::shareDenyNone))
+ {
+ if(phr) *phr = E_FAIL;
+ return;
+ }
+
+ if(m_flic.Read(&m_hdr, sizeof(m_hdr)) != sizeof(m_hdr)
+ || (m_hdr.id != 0xaf11 && m_hdr.id != 0xaf12)
+ || m_hdr.bpp != 8)
+ {
+ if(phr) *phr = E_FAIL;
+ return;
+ }
+
+ m_AvgTimePerFrame = (m_hdr.id == 0xaf11)
+ ? 10000000i64 * max(m_hdr.ticks, 1) / 70
+ : 10000000i64 * max(m_hdr.ticks, 1) / 1000;
+
+ // not tested (lack of test files)
+ {
+ __int64 pos = m_flic.GetPosition();
+ FLIC_PREFIX fp;
+ if(m_flic.Read(&fp, sizeof(fp)) != sizeof(fp) || fp.id != 0xf100)
+ m_flic.Seek(pos, CFile::begin);
+ else
+ m_flic.Seek(pos + fp.size, CFile::begin);
+ }
+
+ do
+ {
+ FLIC_FRAME_ENTRY ffe;
+ if(m_flic.Read(&ffe.hdr, sizeof(ffe.hdr)) != sizeof(ffe.hdr) || ffe.hdr.id != 0xf1fa)
+ break;
+ ffe.pos = m_flic.GetPosition();
+ ffe.fKeyframe = (m_frames.GetCount() == 0);
+
+ int chunk = 0;
+ while(chunk < ffe.hdr.chunks)
+ {
+ FLIC_CHUNK fc;
+ if(m_flic.Read(&fc, sizeof(fc)) != sizeof(fc))
+ break;
+ /*
+ switch(fc.type)
+ {
+ case FLIC_COLOR: _colorchunk(); break;
+ case FLIC_256_COLOR: _color256chunk(); break;
+ case FLIC_BRUN: _brunchunk(); break;
+ case FLIC_LC: _lcchunk(); break;
+ case FLIC_DELTA: _deltachunk(); break;
+ case FLIC_BLACK: _blackchunk(); break;
+ case FLIC_COPY: _copychunk(); break;
+ case FLIC_MINI: break;
+ default: break;
+ }
+ */
+ ffe.fKeyframe =
+ (/*fc.type == FLIC_256_COLOR
|| fc.type == FLIC_64_COLOR
- ||*/ fc.type == FLIC_BRUN
- || fc.type == FLIC_BLACK
- || fc.type == FLIC_COPY);
-
- __int64 pos = m_flic.GetPosition() + fc.size - sizeof(fc);
- if(m_flic.Seek(pos, CFile::begin) != pos)
- break;
-
- chunk++;
- }
- if(chunk < ffe.hdr.chunks)
- break;
-
- __int64 pos = ffe.pos + ffe.hdr.size - sizeof(ffe.hdr);
- if(m_flic.Seek(pos, CFile::begin) != pos)
- break;
-
- m_frames.Add(ffe);
- }
- while(1);
-
- m_nLastFrameNum = -1;
- memset(m_pPalette, 0, sizeof(m_pPalette));
- m_nBufferSize = m_hdr.x*m_hdr.y*32>>3;
- if(!m_pFrameBuffer.Allocate(m_nBufferSize))
- {
- if(phr) *phr = E_OUTOFMEMORY;
- return;
- }
-
- m_rtDuration = m_rtStop = m_AvgTimePerFrame*m_frames.GetCount();
-
- if(phr) *phr = m_rtDuration > 0 ? S_OK : E_FAIL;
+ ||*/ fc.type == FLIC_BRUN
+ || fc.type == FLIC_BLACK
+ || fc.type == FLIC_COPY);
+
+ __int64 pos = m_flic.GetPosition() + fc.size - sizeof(fc);
+ if(m_flic.Seek(pos, CFile::begin) != pos)
+ break;
+
+ chunk++;
+ }
+ if(chunk < ffe.hdr.chunks)
+ break;
+
+ __int64 pos = ffe.pos + ffe.hdr.size - sizeof(ffe.hdr);
+ if(m_flic.Seek(pos, CFile::begin) != pos)
+ break;
+
+ m_frames.Add(ffe);
+ }
+ while(1);
+
+ m_nLastFrameNum = -1;
+ memset(m_pPalette, 0, sizeof(m_pPalette));
+ m_nBufferSize = m_hdr.x * m_hdr.y * 32 >> 3;
+ if(!m_pFrameBuffer.Allocate(m_nBufferSize))
+ {
+ if(phr) *phr = E_OUTOFMEMORY;
+ return;
+ }
+
+ m_rtDuration = m_rtStop = m_AvgTimePerFrame * m_frames.GetCount();
+
+ if(phr) *phr = m_rtDuration > 0 ? S_OK : E_FAIL;
}
CFLICStream::~CFLICStream()
{
- CAutoLock cAutoLock(&m_cSharedState);
+ CAutoLock cAutoLock(&m_cSharedState);
}
STDMETHODIMP CFLICStream::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
CheckPointer(ppv, E_POINTER);
- return (riid == IID_IMediaSeeking) ? CSourceSeeking::NonDelegatingQueryInterface(riid, ppv) //GetInterface((IMediaSeeking*)this, ppv)
- : CSourceStream::NonDelegatingQueryInterface(riid, ppv);
+ return (riid == IID_IMediaSeeking) ? CSourceSeeking::NonDelegatingQueryInterface(riid, ppv) //GetInterface((IMediaSeeking*)this, ppv)
+ : CSourceStream::NonDelegatingQueryInterface(riid, ppv);
}
void CFLICStream::UpdateFromSeek()
{
- if(ThreadExists())
- {
- // next time around the loop, the worker thread will
- // pick up the position change.
- // We need to flush all the existing data - we must do that here
- // as our thread will probably be blocked in GetBuffer otherwise
-
- m_bFlushing = TRUE;
-
- DeliverBeginFlush();
- // make sure we have stopped pushing
- Stop();
- // complete the flush
- DeliverEndFlush();
+ if(ThreadExists())
+ {
+ // next time around the loop, the worker thread will
+ // pick up the position change.
+ // We need to flush all the existing data - we must do that here
+ // as our thread will probably be blocked in GetBuffer otherwise
+
+ m_bFlushing = TRUE;
+
+ DeliverBeginFlush();
+ // make sure we have stopped pushing
+ Stop();
+ // complete the flush
+ DeliverEndFlush();
m_bFlushing = FALSE;
- // restart
- Run();
- }
+ // restart
+ Run();
+ }
}
HRESULT CFLICStream::SetRate(double dRate)
{
- if(dRate <= 0)
- return E_INVALIDARG;
+ if(dRate <= 0)
+ return E_INVALIDARG;
- {
- CAutoLock lock(CSourceSeeking::m_pLock);
- m_dRateSeeking = dRate;
- }
+ {
+ CAutoLock lock(CSourceSeeking::m_pLock);
+ m_dRateSeeking = dRate;
+ }
- UpdateFromSeek();
+ UpdateFromSeek();
- return S_OK;
+ return S_OK;
}
HRESULT CFLICStream::OnThreadStartPlay()
@@ -315,8 +315,8 @@ HRESULT CFLICStream::ChangeStart()
{
{
CAutoLock lock(CSourceSeeking::m_pLock);
- m_rtSampleTime = 0;
- m_rtPosition = m_rtStart;
+ m_rtSampleTime = 0;
+ m_rtPosition = m_rtStart;
}
UpdateFromSeek();
@@ -329,7 +329,7 @@ HRESULT CFLICStream::ChangeStop()
{
CAutoLock lock(CSourceSeeking::m_pLock);
if(m_rtPosition < m_rtStop)
- return S_OK;
+ return S_OK;
}
// We're already past the new stop time -- better flush the graph.
@@ -356,8 +356,8 @@ HRESULT CFLICStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIE
HRESULT hr = NOERROR;
- pProperties->cBuffers = 1;
- pProperties->cbBuffer = m_nBufferSize;
+ pProperties->cBuffers = 1;
+ pProperties->cbBuffer = m_nBufferSize;
ALLOCATOR_PROPERTIES Actual;
if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
@@ -370,71 +370,71 @@ HRESULT CFLICStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIE
HRESULT CFLICStream::FillBuffer(IMediaSample* pSample)
{
- HRESULT hr;
+ HRESULT hr;
- {
- CAutoLock cAutoLockShared(&m_cSharedState);
+ {
+ CAutoLock cAutoLockShared(&m_cSharedState);
if(m_rtPosition >= m_rtStop)
- return S_FALSE;
-
- BYTE* pDataIn = m_pFrameBuffer;
- BYTE* pDataOut = NULL;
- if(!pDataIn || FAILED(hr = pSample->GetPointer(&pDataOut)) || !pDataOut)
- return S_FALSE;
-
- AM_MEDIA_TYPE* pmt;
- if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt)
- {
- CMediaType mt(*pmt);
- SetMediaType(&mt);
-
- DeleteMediaType(pmt);
- }
-
- int w, h, bpp;
- if(m_mt.formattype == FORMAT_VideoInfo)
- {
- w = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biWidth;
- h = abs(((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biHeight);
- bpp = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biBitCount;
- }
- else if(m_mt.formattype == FORMAT_VideoInfo2)
- {
- w = ((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biWidth;
- h = abs(((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biHeight);
- bpp = ((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biBitCount;
- }
- else
- {
- return S_FALSE;
- }
-
- int pitchIn = m_hdr.x;
- int pitchOut = w*bpp>>3;
-
- int nFrame = m_rtPosition / m_AvgTimePerFrame; // (int)(1.0 * m_rtPosition / m_AvgTimePerFrame + 0.5);
-
- {
- SeekToNearestKeyFrame(nFrame);
-
- while(m_nLastFrameNum < nFrame && !m_bFlushing)
- ExtractFrame(++m_nLastFrameNum);
-
- for(int y = 0, p = min(pitchIn, pitchOut);
- y < h;
- y++, pDataIn += pitchIn, pDataOut += pitchOut)
- {
- BYTE* src = pDataIn;
- BYTE* end = src + p;
- DWORD* dst = (DWORD*)pDataOut;
- while(src < end) *dst++ = m_pPalette[*src++];
- }
- }
-
- pSample->SetActualDataLength(pitchOut*h);
-
- REFERENCE_TIME rtStart, rtStop;
+ return S_FALSE;
+
+ BYTE* pDataIn = m_pFrameBuffer;
+ BYTE* pDataOut = NULL;
+ if(!pDataIn || FAILED(hr = pSample->GetPointer(&pDataOut)) || !pDataOut)
+ return S_FALSE;
+
+ AM_MEDIA_TYPE* pmt;
+ if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt)
+ {
+ CMediaType mt(*pmt);
+ SetMediaType(&mt);
+
+ DeleteMediaType(pmt);
+ }
+
+ int w, h, bpp;
+ if(m_mt.formattype == FORMAT_VideoInfo)
+ {
+ w = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biWidth;
+ h = abs(((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biHeight);
+ bpp = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biBitCount;
+ }
+ else if(m_mt.formattype == FORMAT_VideoInfo2)
+ {
+ w = ((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biWidth;
+ h = abs(((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biHeight);
+ bpp = ((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biBitCount;
+ }
+ else
+ {
+ return S_FALSE;
+ }
+
+ int pitchIn = m_hdr.x;
+ int pitchOut = w * bpp >> 3;
+
+ int nFrame = m_rtPosition / m_AvgTimePerFrame; // (int)(1.0 * m_rtPosition / m_AvgTimePerFrame + 0.5);
+
+ {
+ SeekToNearestKeyFrame(nFrame);
+
+ while(m_nLastFrameNum < nFrame && !m_bFlushing)
+ ExtractFrame(++m_nLastFrameNum);
+
+ for(int y = 0, p = min(pitchIn, pitchOut);
+ y < h;
+ y++, pDataIn += pitchIn, pDataOut += pitchOut)
+ {
+ BYTE* src = pDataIn;
+ BYTE* end = src + p;
+ DWORD* dst = (DWORD*)pDataOut;
+ while(src < end) *dst++ = m_pPalette[*src++];
+ }
+ }
+
+ pSample->SetActualDataLength(pitchOut * h);
+
+ REFERENCE_TIME rtStart, rtStop;
// The sample times are modified by the current rate.
rtStart = static_cast<REFERENCE_TIME>(m_rtSampleTime / m_dRateSeeking);
rtStop = rtStart + static_cast<int>(m_AvgTimePerFrame / m_dRateSeeking);
@@ -442,17 +442,17 @@ HRESULT CFLICStream::FillBuffer(IMediaSample* pSample)
m_rtSampleTime += m_AvgTimePerFrame;
m_rtPosition += m_AvgTimePerFrame;
- }
+ }
- pSample->SetSyncPoint(TRUE);
+ pSample->SetSyncPoint(TRUE);
- if(m_bDiscontinuity)
+ if(m_bDiscontinuity)
{
- pSample->SetDiscontinuity(TRUE);
- m_bDiscontinuity = FALSE;
- }
+ pSample->SetDiscontinuity(TRUE);
+ m_bDiscontinuity = FALSE;
+ }
- return S_OK;
+ return S_OK;
}
HRESULT CFLICStream::GetMediaType(int iPosition, CMediaType* pmt)
@@ -467,290 +467,309 @@ HRESULT CFLICStream::GetMediaType(int iPosition, CMediaType* pmt)
pmt->SetFormatType(&FORMAT_VideoInfo);
pmt->SetTemporalCompression(TRUE);
- VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
- memset(vih, 0, sizeof(VIDEOINFOHEADER));
- vih->AvgTimePerFrame = m_AvgTimePerFrame;
- vih->bmiHeader.biSize = sizeof(vih->bmiHeader);
- vih->bmiHeader.biWidth = m_hdr.x;
- vih->bmiHeader.biHeight = -m_hdr.y;
- vih->bmiHeader.biPlanes = 1;
- vih->bmiHeader.biBitCount = 32;
- vih->bmiHeader.biCompression = BI_RGB;
- vih->bmiHeader.biSizeImage = m_nBufferSize;
+ VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
+ memset(vih, 0, sizeof(VIDEOINFOHEADER));
+ vih->AvgTimePerFrame = m_AvgTimePerFrame;
+ vih->bmiHeader.biSize = sizeof(vih->bmiHeader);
+ vih->bmiHeader.biWidth = m_hdr.x;
+ vih->bmiHeader.biHeight = -m_hdr.y;
+ vih->bmiHeader.biPlanes = 1;
+ vih->bmiHeader.biBitCount = 32;
+ vih->bmiHeader.biCompression = BI_RGB;
+ vih->bmiHeader.biSizeImage = m_nBufferSize;
- pmt->SetSampleSize(vih->bmiHeader.biSizeImage);
+ pmt->SetSampleSize(vih->bmiHeader.biSizeImage);
return NOERROR;
}
HRESULT CFLICStream::CheckConnect(IPin* pPin)
{
- return CSourceStream::CheckConnect(pPin);
+ return CSourceStream::CheckConnect(pPin);
}
HRESULT CFLICStream::CheckMediaType(const CMediaType* pmt)
{
- if(pmt->majortype == MEDIATYPE_Video
- && pmt->subtype == MEDIASUBTYPE_RGB32
- && pmt->formattype == FORMAT_VideoInfo) return S_OK;
+ if(pmt->majortype == MEDIATYPE_Video
+ && pmt->subtype == MEDIASUBTYPE_RGB32
+ && pmt->formattype == FORMAT_VideoInfo) return S_OK;
- return E_INVALIDARG;
+ return E_INVALIDARG;
}
STDMETHODIMP CFLICStream::Notify(IBaseFilter* pSender, Quality q)
{
- return E_NOTIMPL;
+ return E_NOTIMPL;
}
////////
void CFLICStream::SeekToNearestKeyFrame(int nFrame)
{
- if(m_nLastFrameNum == nFrame)
- return;
+ if(m_nLastFrameNum == nFrame)
+ return;
- if(m_nLastFrameNum > nFrame)
- m_nLastFrameNum = -1;
+ if(m_nLastFrameNum > nFrame)
+ m_nLastFrameNum = -1;
- for(int i = m_nLastFrameNum+1, j = min(m_frames.GetCount(), nFrame); i < j; i++)
- {
- FLIC_FRAME_ENTRY& ffe = m_frames[i];
- if(ffe.fKeyframe)
- m_nLastFrameNum = i-1;
- }
+ for(int i = m_nLastFrameNum + 1, j = min(m_frames.GetCount(), nFrame); i < j; i++)
+ {
+ FLIC_FRAME_ENTRY& ffe = m_frames[i];
+ if(ffe.fKeyframe)
+ m_nLastFrameNum = i - 1;
+ }
}
void CFLICStream::ExtractFrame(int nFrame)
{
- FLIC_FRAME_ENTRY& ffe = m_frames[nFrame];
+ FLIC_FRAME_ENTRY& ffe = m_frames[nFrame];
- bool fNewPalette = false;
- bool fNewFrame = false;
+ bool fNewPalette = false;
+ bool fNewFrame = false;
- m_flic.Seek(ffe.pos, CFile::begin);
+ m_flic.Seek(ffe.pos, CFile::begin);
- int chunk = 0;
- while(chunk < ffe.hdr.chunks)
- {
- FLIC_CHUNK fc;
- if(m_flic.Read(&fc, sizeof(fc)) != sizeof(fc))
- break;
-
- __int64 next = m_flic.GetPosition() + fc.size - sizeof(fc);
-
- switch(fc.type)
- {
- case FLIC_64_COLOR: fNewPalette = _colorchunk(true); break;
- case FLIC_256_COLOR: fNewPalette = _colorchunk(false); break;
- case FLIC_BRUN: _brunchunk(); fNewFrame = true; break;
- case FLIC_LC: _lcchunk(); break;
- case FLIC_DELTA: _deltachunk(); break;
- case FLIC_BLACK: _blackchunk(); fNewFrame = true; break;
- case FLIC_COPY: _copychunk(); fNewFrame = true; break;
- case FLIC_MINI: break;
- default: break;
- }
-
- if(m_flic.Seek(next, CFile::begin) != next)
- break;
-
- chunk++;
- }
+ int chunk = 0;
+ while(chunk < ffe.hdr.chunks)
+ {
+ FLIC_CHUNK fc;
+ if(m_flic.Read(&fc, sizeof(fc)) != sizeof(fc))
+ break;
+
+ __int64 next = m_flic.GetPosition() + fc.size - sizeof(fc);
+
+ switch(fc.type)
+ {
+ case FLIC_64_COLOR:
+ fNewPalette = _colorchunk(true);
+ break;
+ case FLIC_256_COLOR:
+ fNewPalette = _colorchunk(false);
+ break;
+ case FLIC_BRUN:
+ _brunchunk();
+ fNewFrame = true;
+ break;
+ case FLIC_LC:
+ _lcchunk();
+ break;
+ case FLIC_DELTA:
+ _deltachunk();
+ break;
+ case FLIC_BLACK:
+ _blackchunk();
+ fNewFrame = true;
+ break;
+ case FLIC_COPY:
+ _copychunk();
+ fNewFrame = true;
+ break;
+ case FLIC_MINI:
+ break;
+ default:
+ break;
+ }
+
+ if(m_flic.Seek(next, CFile::begin) != next)
+ break;
+
+ chunk++;
+ }
- if(chunk < ffe.hdr.chunks)
- ASSERT(0);
+ if(chunk < ffe.hdr.chunks)
+ ASSERT(0);
- ffe.fKeyframe = (fNewPalette && fNewFrame);
+ ffe.fKeyframe = (fNewPalette && fNewFrame);
}
void CFLICStream::_blackchunk()
{
- memset(m_pFrameBuffer, 0, m_nBufferSize);
+ memset(m_pFrameBuffer, 0, m_nBufferSize);
}
void CFLICStream::_copychunk()
{
- m_flic.Read(m_pFrameBuffer, m_nBufferSize);
+ m_flic.Read(m_pFrameBuffer, m_nBufferSize);
}
bool CFLICStream::_colorchunk(bool f64)
{
- int nColorsUpdated = 0;
-
- BYTE skip = 0;
-
- WORD packets;
- m_flic.Read(&packets, sizeof(packets));
-
- while(packets--)
- {
- BYTE skip2;
- m_flic.Read(&skip2, sizeof(skip2));
- skip += skip2;
-
- BYTE count;
- m_flic.Read(&count, sizeof(count));
-
- int len = (count == 0 ? (256-skip) : count);
- while(len-- > 0)
- {
- BYTE r, g, b;
- m_flic.Read(&r, sizeof(r));
- m_flic.Read(&g, sizeof(g));
- m_flic.Read(&b, sizeof(b));
- m_pPalette[skip++] = f64
- ? ((r << 18)&0xff0000) | ((g << 10)&0xff00) | ((b << 2)&0xff)
- : ((r << 16)&0xff0000) | ((g << 8)&0xff00) | ((b << 0)&0xff);
- nColorsUpdated++;
- }
- }
-
- return(nColorsUpdated == 256);
+ int nColorsUpdated = 0;
+
+ BYTE skip = 0;
+
+ WORD packets;
+ m_flic.Read(&packets, sizeof(packets));
+
+ while(packets--)
+ {
+ BYTE skip2;
+ m_flic.Read(&skip2, sizeof(skip2));
+ skip += skip2;
+
+ BYTE count;
+ m_flic.Read(&count, sizeof(count));
+
+ int len = (count == 0 ? (256 - skip) : count);
+ while(len-- > 0)
+ {
+ BYTE r, g, b;
+ m_flic.Read(&r, sizeof(r));
+ m_flic.Read(&g, sizeof(g));
+ m_flic.Read(&b, sizeof(b));
+ m_pPalette[skip++] = f64
+ ? ((r << 18) & 0xff0000) | ((g << 10) & 0xff00) | ((b << 2) & 0xff)
+ : ((r << 16) & 0xff0000) | ((g << 8) & 0xff00) | ((b << 0) & 0xff);
+ nColorsUpdated++;
+ }
+ }
+
+ return(nColorsUpdated == 256);
}
void CFLICStream::_brunchunk()
{
- BYTE* tmp = m_pFrameBuffer;
-
- int lines = m_hdr.y;
- while(lines--)
- {
- BYTE packets;
- m_flic.Read(&packets, sizeof(packets));
-
- BYTE* ptr = tmp;
-
- while(ptr < tmp + m_hdr.x)
- {
- signed char count;
- m_flic.Read(&count, sizeof(count));
-
- if(count >= 0)
- {
- BYTE c;
- m_flic.Read(&c, sizeof(c));
- memset(ptr, c, count);
- ptr += count;
- }
- else
- {
- m_flic.Read(ptr, -count);
- ptr += -count;
- }
- }
-
- tmp += m_hdr.x;
- }
+ BYTE* tmp = m_pFrameBuffer;
+
+ int lines = m_hdr.y;
+ while(lines--)
+ {
+ BYTE packets;
+ m_flic.Read(&packets, sizeof(packets));
+
+ BYTE* ptr = tmp;
+
+ while(ptr < tmp + m_hdr.x)
+ {
+ signed char count;
+ m_flic.Read(&count, sizeof(count));
+
+ if(count >= 0)
+ {
+ BYTE c;
+ m_flic.Read(&c, sizeof(c));
+ memset(ptr, c, count);
+ ptr += count;
+ }
+ else
+ {
+ m_flic.Read(ptr, -count);
+ ptr += -count;
+ }
+ }
+
+ tmp += m_hdr.x;
+ }
}
void CFLICStream::_lcchunk()
{
- WORD y;
- m_flic.Read(&y, sizeof(y));
-
- BYTE* tmp = &m_pFrameBuffer[y*m_hdr.x];
-
- WORD lines;
- m_flic.Read(&lines, sizeof(lines));
-
- while(lines--)
- {
- BYTE* ptr = tmp;
+ WORD y;
+ m_flic.Read(&y, sizeof(y));
- BYTE packets;
- m_flic.Read(&packets, sizeof(packets));
+ BYTE* tmp = &m_pFrameBuffer[y*m_hdr.x];
- while(packets--)
- {
- BYTE skip;
- m_flic.Read(&skip, sizeof(skip));
+ WORD lines;
+ m_flic.Read(&lines, sizeof(lines));
- ptr += skip;
-
- signed char count;
- m_flic.Read(&count, sizeof(count));
-
- if(count >= 0)
- {
- m_flic.Read(ptr, count);
- ptr += count;
- }
- else
- {
- BYTE c;
- m_flic.Read(&c, sizeof(c));
- memset(ptr, c, -count);
- ptr += -count;
- }
- }
-
- tmp += m_hdr.x;
- }
+ while(lines--)
+ {
+ BYTE* ptr = tmp;
+
+ BYTE packets;
+ m_flic.Read(&packets, sizeof(packets));
+
+ while(packets--)
+ {
+ BYTE skip;
+ m_flic.Read(&skip, sizeof(skip));
+
+ ptr += skip;
+
+ signed char count;
+ m_flic.Read(&count, sizeof(count));
+
+ if(count >= 0)
+ {
+ m_flic.Read(ptr, count);
+ ptr += count;
+ }
+ else
+ {
+ BYTE c;
+ m_flic.Read(&c, sizeof(c));
+ memset(ptr, c, -count);
+ ptr += -count;
+ }
+ }
+
+ tmp += m_hdr.x;
+ }
}
void CFLICStream::_deltachunk()
{
- BYTE* tmp = m_pFrameBuffer;
-
- WORD lines;
- m_flic.Read(&lines, sizeof(lines));
-
- while(lines--)
- {
- signed short packets;
- m_flic.Read(&packets, sizeof(packets));
-
- if(packets < 0)
- {
- if(packets&0x4000)
- {
- tmp += -packets * m_hdr.x;
- lines++;
- }
- else
- {
- signed char count;
- m_flic.Read(&count, sizeof(count));
- tmp[m_hdr.x-1] = (BYTE)packets;
- }
- }
- else
- {
- BYTE* ptr = tmp;
-
- while(packets--)
- {
- BYTE skip;
- m_flic.Read(&skip, sizeof(skip));
-
- ptr += skip;
-
- signed char count;
- m_flic.Read(&count, sizeof(count));
-
- if(count >= 0)
- {
- // Fix vulnerability : http://www.team509.com/modules.php?name=News&file=article&sid=38
- if ((count << 1) + (long)(ptr - m_pFrameBuffer) < m_nBufferSize)
- m_flic.Read(ptr, count << 1);
- else
- ASSERT(FALSE);
- ptr += count << 1;
- }
- else
- {
- WORD c;
- m_flic.Read(&c, sizeof(c));
- count = -count;
- while(count-- > 0)
- {
- *ptr++ = c>>8;
- *ptr++ = c&0xff;
- }
- }
- }
-
- tmp += m_hdr.x;
- }
- }
+ BYTE* tmp = m_pFrameBuffer;
+
+ WORD lines;
+ m_flic.Read(&lines, sizeof(lines));
+
+ while(lines--)
+ {
+ signed short packets;
+ m_flic.Read(&packets, sizeof(packets));
+
+ if(packets < 0)
+ {
+ if(packets & 0x4000)
+ {
+ tmp += -packets * m_hdr.x;
+ lines++;
+ }
+ else
+ {
+ signed char count;
+ m_flic.Read(&count, sizeof(count));
+ tmp[m_hdr.x-1] = (BYTE)packets;
+ }
+ }
+ else
+ {
+ BYTE* ptr = tmp;
+
+ while(packets--)
+ {
+ BYTE skip;
+ m_flic.Read(&skip, sizeof(skip));
+
+ ptr += skip;
+
+ signed char count;
+ m_flic.Read(&count, sizeof(count));
+
+ if(count >= 0)
+ {
+ // Fix vulnerability : http://www.team509.com/modules.php?name=News&file=article&sid=38
+ if((count << 1) + (long)(ptr - m_pFrameBuffer) < m_nBufferSize)
+ m_flic.Read(ptr, count << 1);
+ else
+ ASSERT(FALSE);
+ ptr += count << 1;
+ }
+ else
+ {
+ WORD c;
+ m_flic.Read(&c, sizeof(c));
+ count = -count;
+ while(count-- > 0)
+ {
+ *ptr++ = c >> 8;
+ *ptr++ = c & 0xff;
+ }
+ }
+ }
+
+ tmp += m_hdr.x;
+ }
+ }
}
diff --git a/src/filters/source/FLICSource/FLICSource.h b/src/filters/source/FLICSource/FLICSource.h
index acbade1e8..801f69286 100644
--- a/src/filters/source/FLICSource/FLICSource.h
+++ b/src/filters/source/FLICSource/FLICSource.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
@@ -26,131 +26,134 @@
#pragma pack(push, 1)
enum
{
- FLIC_256_COLOR = 4,
- FLIC_DELTA = 7,
- FLIC_64_COLOR = 11,
- FLIC_LC = 12,
- FLIC_BLACK = 13,
- FLIC_BRUN = 15,
- FLIC_COPY = 16,
- FLIC_MINI = 18
+ FLIC_256_COLOR = 4,
+ FLIC_DELTA = 7,
+ FLIC_64_COLOR = 11,
+ FLIC_LC = 12,
+ FLIC_BLACK = 13,
+ FLIC_BRUN = 15,
+ FLIC_COPY = 16,
+ FLIC_MINI = 18
};
-
+
struct FLIC
{
- DWORD size;
- WORD id; // 0xaf11 or 0xaf12
- WORD frames, x, y, bpp;
- WORD flags, ticks;
- DWORD next, frit;
- BYTE reserved[102];
+ DWORD size;
+ WORD id; // 0xaf11 or 0xaf12
+ WORD frames, x, y, bpp;
+ WORD flags, ticks;
+ DWORD next, frit;
+ BYTE reserved[102];
};
struct FLIC_PREFIX
{
- DWORD size;
- WORD id; // 0xf100
- WORD chunks;
- BYTE reserved[8];
+ DWORD size;
+ WORD id; // 0xf100
+ WORD chunks;
+ BYTE reserved[8];
};
struct FLIC_FRAME
{
- DWORD size;
- WORD id; // 0xf1fa
- WORD chunks;
- BYTE reserved[8];
+ DWORD size;
+ WORD id; // 0xf1fa
+ WORD chunks;
+ BYTE reserved[8];
};
struct FLIC_CHUNK
{
- DWORD size;
- WORD type;
+ DWORD size;
+ WORD type;
};
#pragma pack(pop)
struct FLIC_FRAME_ENTRY
{
- __int64 pos;
- bool fKeyframe;
- FLIC_FRAME hdr;
+ __int64 pos;
+ bool fKeyframe;
+ FLIC_FRAME hdr;
};
[uuid("17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4")]
class CFLICSource
- : public CSource
- , public IFileSourceFilter
- , public IAMFilterMiscFlags
+ : public CSource
+ , public IFileSourceFilter
+ , public IAMFilterMiscFlags
{
- CStringW m_fn;
+ CStringW m_fn;
public:
- CFLICSource(LPUNKNOWN lpunk, HRESULT* phr);
- virtual ~CFLICSource();
+ CFLICSource(LPUNKNOWN lpunk, HRESULT* phr);
+ virtual ~CFLICSource();
- DECLARE_IUNKNOWN;
+ DECLARE_IUNKNOWN;
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
- // IFileSourceFilter
- STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt);
- STDMETHODIMP GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt);
+ // IFileSourceFilter
+ STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt);
+ STDMETHODIMP GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt);
- // IAMFilterMiscFlags
- STDMETHODIMP_(ULONG) GetMiscFlags();
+ // IAMFilterMiscFlags
+ STDMETHODIMP_(ULONG) GetMiscFlags();
};
-class CFLICStream
- : public CSourceStream
- , public CSourceSeeking
+class CFLICStream
+ : public CSourceStream
+ , public CSourceSeeking
{
- CFile m_flic;
- FLIC m_hdr;
- CAtlArray<FLIC_FRAME_ENTRY> m_frames;
+ CFile m_flic;
+ FLIC m_hdr;
+ CAtlArray<FLIC_FRAME_ENTRY> m_frames;
- CCritSec m_cSharedState;
+ CCritSec m_cSharedState;
- REFERENCE_TIME m_AvgTimePerFrame;
- REFERENCE_TIME m_rtSampleTime, m_rtPosition;
+ REFERENCE_TIME m_AvgTimePerFrame;
+ REFERENCE_TIME m_rtSampleTime, m_rtPosition;
- BOOL m_bDiscontinuity, m_bFlushing;
+ BOOL m_bDiscontinuity, m_bFlushing;
- HRESULT OnThreadStartPlay();
- HRESULT OnThreadCreate();
+ HRESULT OnThreadStartPlay();
+ HRESULT OnThreadCreate();
- void UpdateFromSeek();
- STDMETHODIMP SetRate(double dRate);
+ void UpdateFromSeek();
+ STDMETHODIMP SetRate(double dRate);
- HRESULT ChangeStart();
+ HRESULT ChangeStart();
HRESULT ChangeStop();
- HRESULT ChangeRate() {return S_OK;}
+ HRESULT ChangeRate()
+ {
+ return S_OK;
+ }
private:
- int m_nLastFrameNum;
- DWORD m_pPalette[256];
- CAutoVectorPtr<BYTE> m_pFrameBuffer;
- int m_nBufferSize;
-
- void SeekToNearestKeyFrame(int nFrame);
- void ExtractFrame(int nFrame);
- void _blackchunk();
- void _copychunk();
- bool _colorchunk(bool f64);
- void _brunchunk();
- void _lcchunk();
- void _deltachunk();
+ int m_nLastFrameNum;
+ DWORD m_pPalette[256];
+ CAutoVectorPtr<BYTE> m_pFrameBuffer;
+ int m_nBufferSize;
+
+ void SeekToNearestKeyFrame(int nFrame);
+ void ExtractFrame(int nFrame);
+ void _blackchunk();
+ void _copychunk();
+ bool _colorchunk(bool f64);
+ void _brunchunk();
+ void _lcchunk();
+ void _deltachunk();
public:
CFLICStream(const WCHAR* wfn, CFLICSource* pParent, HRESULT* phr);
- virtual ~CFLICStream();
+ virtual ~CFLICStream();
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
HRESULT FillBuffer(IMediaSample* pSample);
- HRESULT CheckConnect(IPin* pPin);
+ HRESULT CheckConnect(IPin* pPin);
HRESULT CheckMediaType(const CMediaType* pMediaType);
HRESULT GetMediaType(int iPosition, CMediaType* pmt);
-
- STDMETHODIMP Notify(IBaseFilter* pSender, Quality q);
+
+ STDMETHODIMP Notify(IBaseFilter* pSender, Quality q);
};
diff --git a/src/filters/source/FLICSource/resource.h b/src/filters/source/FLICSource/resource.h
index 43aa0620e..4cd977803 100644
--- a/src/filters/source/FLICSource/resource.h
+++ b/src/filters/source/FLICSource/resource.h
@@ -3,7 +3,7 @@
// Used by flicsource.rc
// Next default values for new objects
-//
+//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
diff --git a/src/filters/source/FLICSource/stdafx.cpp b/src/filters/source/FLICSource/stdafx.cpp
index 5158d6e51..c60551b94 100644
--- a/src/filters/source/FLICSource/stdafx.cpp
+++ b/src/filters/source/FLICSource/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
diff --git a/src/filters/source/FLICSource/stdafx.h b/src/filters/source/FLICSource/stdafx.h
index c35359c38..a9f666228 100644
--- a/src/filters/source/FLICSource/stdafx.h
+++ b/src/filters/source/FLICSource/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
diff --git a/src/filters/source/FlacSource/FlacSource.cpp b/src/filters/source/FlacSource/FlacSource.cpp
index 5283edfd1..a1e07d0b7 100644
--- a/src/filters/source/FlacSource/FlacSource.cpp
+++ b/src/filters/source/FlacSource/FlacSource.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
@@ -35,49 +35,49 @@
const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
{
- {&MEDIATYPE_Audio, &MEDIASUBTYPE_FLAC_FRAMED}
+ {&MEDIATYPE_Audio, &MEDIASUBTYPE_FLAC_FRAMED}
};
const AMOVIESETUP_PIN sudOpPin[] =
{
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
const AMOVIESETUP_FILTER sudFilter[] =
{
- {&__uuidof(CFlacSource), L"MPC - Flac Source", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
+ {&__uuidof(CFlacSource), L"MPC - Flac Source", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
};
CFactoryTemplate g_Templates[] =
{
- {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CFlacSource>, NULL, &sudFilter[0]}
+ {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CFlacSource>, NULL, &sudFilter[0]}
};
int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
- SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"),
- _T("0"), _T("0,4,,664C6143"));
+ SetRegKeyValue(
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"),
+ _T("0"), _T("0,4,,664C6143"));
- SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"),
- _T("Source Filter"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"));
+ SetRegKeyValue(
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"),
+ _T("Source Filter"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"));
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".flac"),
- _T("Source Filter"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"));
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".flac"),
+ _T("Source Filter"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"));
- return AMovieDllRegisterServer2(TRUE);
+ return AMovieDllRegisterServer2(TRUE);
}
STDAPI DllUnregisterServer()
{
- DeleteRegKey(_T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"));
- DeleteRegKey(_T("Media Type\\Extensions"), _T(".flac"));
+ DeleteRegKey(_T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"));
+ DeleteRegKey(_T("Media Type\\Extensions"), _T(".flac"));
- return AMovieDllRegisterServer2(FALSE);
+ return AMovieDllRegisterServer2(FALSE);
}
#include "../../FilterApp.h"
@@ -103,7 +103,7 @@ static void StreamDecoderMetadata(const FLAC__StreamDecoder *decoder, con
//
CFlacSource::CFlacSource(LPUNKNOWN lpunk, HRESULT* phr)
- : CBaseSource<CFlacStream>(NAME("CFlacSource"), lpunk, phr, __uuidof(this))
+ : CBaseSource<CFlacStream>(NAME("CFlacSource"), lpunk, phr, __uuidof(this))
{
}
@@ -113,51 +113,52 @@ CFlacSource::~CFlacSource()
// CFlacStream
-CFlacStream::CFlacStream(const WCHAR* wfn, CSource* pParent, HRESULT* phr)
- : CBaseStream(NAME("CFlacStream"), pParent, phr)
- , m_bIsEOF (false)
+CFlacStream::CFlacStream(const WCHAR* wfn, CSource* pParent, HRESULT* phr)
+ : CBaseStream(NAME("CFlacStream"), pParent, phr)
+ , m_bIsEOF(false)
{
- CAutoLock cAutoLock(&m_cSharedState);
- CString fn(wfn);
- CFileException ex;
- HRESULT hr = E_FAIL;
-
- do
- {
- if(!m_file.Open(fn, CFile::modeRead|CFile::shareDenyNone, &ex))
- {
- hr = AmHresultFromWin32 (ex.m_lOsError);
- break;
- }
-
- m_pDecoder = FLAC__stream_decoder_new();
- if (!m_pDecoder) break;
-
- if (FLAC__STREAM_DECODER_INIT_STATUS_OK != FLAC__stream_decoder_init_stream (_DECODER_,
- StreamDecoderRead,
- StreamDecoderSeek,
- StreamDecoderTell,
- StreamDecoderLength,
- StreamDecoderEof,
- StreamDecoderWrite,
- StreamDecoderMetadata,
- StreamDecoderError,
- this))
- {
- break;
- }
-
-
- if (!FLAC__stream_decoder_process_until_end_of_metadata (_DECODER_) ||
- !FLAC__stream_decoder_seek_absolute (_DECODER_, 0))
- break;
-
- FLAC__stream_decoder_get_decode_position(_DECODER_, &m_llOffset);
-
- hr = S_OK;
- } while (false);
-
- if(phr) *phr = hr;
+ CAutoLock cAutoLock(&m_cSharedState);
+ CString fn(wfn);
+ CFileException ex;
+ HRESULT hr = E_FAIL;
+
+ do
+ {
+ if(!m_file.Open(fn, CFile::modeRead | CFile::shareDenyNone, &ex))
+ {
+ hr = AmHresultFromWin32(ex.m_lOsError);
+ break;
+ }
+
+ m_pDecoder = FLAC__stream_decoder_new();
+ if(!m_pDecoder) break;
+
+ if(FLAC__STREAM_DECODER_INIT_STATUS_OK != FLAC__stream_decoder_init_stream(_DECODER_,
+ StreamDecoderRead,
+ StreamDecoderSeek,
+ StreamDecoderTell,
+ StreamDecoderLength,
+ StreamDecoderEof,
+ StreamDecoderWrite,
+ StreamDecoderMetadata,
+ StreamDecoderError,
+ this))
+ {
+ break;
+ }
+
+
+ if(!FLAC__stream_decoder_process_until_end_of_metadata(_DECODER_) ||
+ !FLAC__stream_decoder_seek_absolute(_DECODER_, 0))
+ break;
+
+ FLAC__stream_decoder_get_decode_position(_DECODER_, &m_llOffset);
+
+ hr = S_OK;
+ }
+ while(false);
+
+ if(phr) *phr = hr;
}
CFlacStream::~CFlacStream()
@@ -172,8 +173,8 @@ HRESULT CFlacStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIE
HRESULT hr = NOERROR;
- pProperties->cBuffers = 1;
- pProperties->cbBuffer = m_nMaxFrameSize;
+ pProperties->cBuffers = 1;
+ pProperties->cbBuffer = m_nMaxFrameSize;
ALLOCATOR_PROPERTIES Actual;
if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
@@ -186,33 +187,33 @@ HRESULT CFlacStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIE
HRESULT CFlacStream::FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len)
{
- FLAC__uint64 llCurPos;
- FLAC__uint64 llNextPos;
+ FLAC__uint64 llCurPos;
+ FLAC__uint64 llNextPos;
- if (m_bDiscontinuity)
- {
- FLAC__stream_decoder_seek_absolute (_DECODER_, (m_rtPosition * m_i64TotalNumSamples) / m_rtDuration);
- }
+ if(m_bDiscontinuity)
+ {
+ FLAC__stream_decoder_seek_absolute(_DECODER_, (m_rtPosition * m_i64TotalNumSamples) / m_rtDuration);
+ }
- FLAC__stream_decoder_get_decode_position(_DECODER_, &llCurPos);
-
- FLAC__stream_decoder_skip_single_frame (_DECODER_);
- if (m_bIsEOF)
- return S_FALSE;
- FLAC__stream_decoder_get_decode_position(_DECODER_, &llNextPos);
+ FLAC__stream_decoder_get_decode_position(_DECODER_, &llCurPos);
- FLAC__uint64 llCurFile = m_file.GetPosition();
- len = llNextPos - llCurPos;
- ASSERT (len > 0);
- if (len <= 0) return S_FALSE;
+ FLAC__stream_decoder_skip_single_frame(_DECODER_);
+ if(m_bIsEOF)
+ return S_FALSE;
+ FLAC__stream_decoder_get_decode_position(_DECODER_, &llNextPos);
- m_file.Seek (llCurPos, CFile::begin);
- m_file.Read (pOut, len);
- m_file.Seek (llCurFile, CFile::begin);
+ FLAC__uint64 llCurFile = m_file.GetPosition();
+ len = llNextPos - llCurPos;
+ ASSERT(len > 0);
+ if(len <= 0) return S_FALSE;
- m_AvgTimePerFrame = m_rtDuration * len / (m_llFileSize-m_llOffset);
+ m_file.Seek(llCurPos, CFile::begin);
+ m_file.Read(pOut, len);
+ m_file.Seek(llCurFile, CFile::begin);
- return S_OK;
+ m_AvgTimePerFrame = m_rtDuration * len / (m_llFileSize - m_llOffset);
+
+ return S_OK;
}
@@ -221,118 +222,118 @@ HRESULT CFlacStream::GetMediaType(int iPosition, CMediaType* pmt)
{
CAutoLock cAutoLock(m_pFilter->pStateLock());
- if(iPosition == 0)
- {
- pmt->majortype = MEDIATYPE_Audio;
- pmt->subtype = MEDIASUBTYPE_FLAC_FRAMED;
- pmt->formattype = FORMAT_WaveFormatEx;
- WAVEFORMATEX* wfe = (WAVEFORMATEX*)pmt->AllocFormatBuffer(sizeof(WAVEFORMATEX));
- memset(wfe, 0, sizeof(WAVEFORMATEX));
- wfe->cbSize = sizeof(WAVEFORMATEX);
- wfe->wFormatTag = WAVE_FORMAT_FLAC;
- wfe->nSamplesPerSec = m_nSamplesPerSec;
- wfe->nAvgBytesPerSec = m_nAvgBytesPerSec;
- wfe->nChannels = m_nChannels;
- wfe->nBlockAlign = 1;
- wfe->wBitsPerSample = m_wBitsPerSample;
- }
- else
- {
- return VFW_S_NO_MORE_ITEMS;
- }
+ if(iPosition == 0)
+ {
+ pmt->majortype = MEDIATYPE_Audio;
+ pmt->subtype = MEDIASUBTYPE_FLAC_FRAMED;
+ pmt->formattype = FORMAT_WaveFormatEx;
+ WAVEFORMATEX* wfe = (WAVEFORMATEX*)pmt->AllocFormatBuffer(sizeof(WAVEFORMATEX));
+ memset(wfe, 0, sizeof(WAVEFORMATEX));
+ wfe->cbSize = sizeof(WAVEFORMATEX);
+ wfe->wFormatTag = WAVE_FORMAT_FLAC;
+ wfe->nSamplesPerSec = m_nSamplesPerSec;
+ wfe->nAvgBytesPerSec = m_nAvgBytesPerSec;
+ wfe->nChannels = m_nChannels;
+ wfe->nBlockAlign = 1;
+ wfe->wBitsPerSample = m_wBitsPerSample;
+ }
+ else
+ {
+ return VFW_S_NO_MORE_ITEMS;
+ }
pmt->SetTemporalCompression(FALSE);
- return S_OK;
+ return S_OK;
}
HRESULT CFlacStream::CheckMediaType(const CMediaType* pmt)
{
- if ( pmt->majortype == MEDIATYPE_Audio
- && pmt->subtype == MEDIASUBTYPE_FLAC_FRAMED
- && pmt->formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_FLAC)
- return S_OK;
- else
- return E_INVALIDARG;
+ if(pmt->majortype == MEDIATYPE_Audio
+ && pmt->subtype == MEDIASUBTYPE_FLAC_FRAMED
+ && pmt->formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_FLAC)
+ return S_OK;
+ else
+ return E_INVALIDARG;
}
-void CFlacStream::UpdateFromMetadata (void* pBuffer)
+void CFlacStream::UpdateFromMetadata(void* pBuffer)
{
- const FLAC__StreamMetadata* pMetadata = (const FLAC__StreamMetadata*) pBuffer;
-
- m_nMaxFrameSize = pMetadata->data.stream_info.max_framesize;
- m_nSamplesPerSec = pMetadata->data.stream_info.sample_rate;
- m_nChannels = pMetadata->data.stream_info.channels;
- m_wBitsPerSample = pMetadata->data.stream_info.bits_per_sample;
- m_i64TotalNumSamples = pMetadata->data.stream_info.total_samples;
- m_nAvgBytesPerSec = (m_nChannels * (m_wBitsPerSample >> 3)) * m_nSamplesPerSec;
-
- // === Init members from base classes
- GetFileSizeEx (m_file.m_hFile, (LARGE_INTEGER*)&m_llFileSize);
- m_rtDuration = (m_i64TotalNumSamples * UNITS) / m_nSamplesPerSec;
- m_rtStop = m_rtDuration;
- m_AvgTimePerFrame = (m_nMaxFrameSize + pMetadata->data.stream_info.min_framesize) * m_rtDuration / 2 / m_llFileSize;
+ const FLAC__StreamMetadata* pMetadata = (const FLAC__StreamMetadata*) pBuffer;
+
+ m_nMaxFrameSize = pMetadata->data.stream_info.max_framesize;
+ m_nSamplesPerSec = pMetadata->data.stream_info.sample_rate;
+ m_nChannels = pMetadata->data.stream_info.channels;
+ m_wBitsPerSample = pMetadata->data.stream_info.bits_per_sample;
+ m_i64TotalNumSamples = pMetadata->data.stream_info.total_samples;
+ m_nAvgBytesPerSec = (m_nChannels * (m_wBitsPerSample >> 3)) * m_nSamplesPerSec;
+
+ // === Init members from base classes
+ GetFileSizeEx(m_file.m_hFile, (LARGE_INTEGER*)&m_llFileSize);
+ m_rtDuration = (m_i64TotalNumSamples * UNITS) / m_nSamplesPerSec;
+ m_rtStop = m_rtDuration;
+ m_AvgTimePerFrame = (m_nMaxFrameSize + pMetadata->data.stream_info.min_framesize) * m_rtDuration / 2 / m_llFileSize;
}
FLAC__StreamDecoderReadStatus StreamDecoderRead(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
{
- CFlacStream* pThis = static_cast<CFlacStream*> (client_data);
- UINT nRead;
+ CFlacStream* pThis = static_cast<CFlacStream*>(client_data);
+ UINT nRead;
- nRead = pThis->GetFile()->Read (buffer, *bytes);
- pThis->m_bIsEOF = (nRead != *bytes);
- *bytes = nRead;
+ nRead = pThis->GetFile()->Read(buffer, *bytes);
+ pThis->m_bIsEOF = (nRead != *bytes);
+ *bytes = nRead;
- return (*bytes == 0) ? FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM : FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+ return (*bytes == 0) ? FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM : FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
FLAC__StreamDecoderSeekStatus StreamDecoderSeek(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
{
- CFlacStream* pThis = static_cast<CFlacStream*> (client_data);
-
- pThis->m_bIsEOF = false;
- pThis->GetFile()->Seek (absolute_byte_offset, CFile::begin);
- return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
+ CFlacStream* pThis = static_cast<CFlacStream*>(client_data);
+
+ pThis->m_bIsEOF = false;
+ pThis->GetFile()->Seek(absolute_byte_offset, CFile::begin);
+ return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
}
FLAC__StreamDecoderTellStatus StreamDecoderTell(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
{
- CFlacStream* pThis = static_cast<CFlacStream*> (client_data);
- *absolute_byte_offset = pThis->GetFile()->GetPosition();
- return FLAC__STREAM_DECODER_TELL_STATUS_OK;
+ CFlacStream* pThis = static_cast<CFlacStream*>(client_data);
+ *absolute_byte_offset = pThis->GetFile()->GetPosition();
+ return FLAC__STREAM_DECODER_TELL_STATUS_OK;
}
FLAC__StreamDecoderLengthStatus StreamDecoderLength(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
{
- CFlacStream* pThis = static_cast<CFlacStream*> (client_data);
- CFile* pFile = pThis->GetFile();
-
- if (pFile == NULL)
- return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
- else
- {
- *stream_length = pFile->GetLength();
- return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
- }
+ CFlacStream* pThis = static_cast<CFlacStream*>(client_data);
+ CFile* pFile = pThis->GetFile();
+
+ if(pFile == NULL)
+ return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
+ else
+ {
+ *stream_length = pFile->GetLength();
+ return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
+ }
}
FLAC__bool StreamDecoderEof(const FLAC__StreamDecoder *decoder, void *client_data)
{
- CFlacStream* pThis = static_cast<CFlacStream*> (client_data);
+ CFlacStream* pThis = static_cast<CFlacStream*>(client_data);
- return pThis->m_bIsEOF;
+ return pThis->m_bIsEOF;
}
FLAC__StreamDecoderWriteStatus StreamDecoderWrite(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
{
- CFlacStream* pThis = static_cast<CFlacStream*> (client_data);
+ CFlacStream* pThis = static_cast<CFlacStream*>(client_data);
- return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+ return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
void StreamDecoderError(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
@@ -342,8 +343,8 @@ void StreamDecoderError(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderE
void StreamDecoderMetadata(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
{
- CFlacStream* pThis = static_cast<CFlacStream*> (client_data);
+ CFlacStream* pThis = static_cast<CFlacStream*>(client_data);
- if (pThis)
- pThis->UpdateFromMetadata ((void*)metadata);
+ if(pThis)
+ pThis->UpdateFromMetadata((void*)metadata);
}
diff --git a/src/filters/source/FlacSource/FlacSource.h b/src/filters/source/FlacSource/FlacSource.h
index 3b7f87969..f7c4ce5a0 100644
--- a/src/filters/source/FlacSource/FlacSource.h
+++ b/src/filters/source/FlacSource/FlacSource.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
@@ -30,8 +30,8 @@ class CFlacStream;
class CFlacSource : public CBaseSource<CFlacStream>
{
public:
- CFlacSource(LPUNKNOWN lpunk, HRESULT* phr);
- virtual ~CFlacSource();
+ CFlacSource(LPUNKNOWN lpunk, HRESULT* phr);
+ virtual ~CFlacSource();
};
@@ -39,31 +39,34 @@ class CGolombBuffer;
class CFlacStream : public CBaseStream
{
- CFile m_file;
- void* m_pDecoder;
+ CFile m_file;
+ void* m_pDecoder;
- int m_nMaxFrameSize;
- int m_nSamplesPerSec;
- int m_nChannels;
- WORD m_wBitsPerSample;
- __int64 m_i64TotalNumSamples;
- int m_nAvgBytesPerSec;
+ int m_nMaxFrameSize;
+ int m_nSamplesPerSec;
+ int m_nChannels;
+ WORD m_wBitsPerSample;
+ __int64 m_i64TotalNumSamples;
+ int m_nAvgBytesPerSec;
- ULONGLONG m_llOffset; // Position of first frame in file
- ULONGLONG m_llFileSize; // Size of the file
+ ULONGLONG m_llOffset; // Position of first frame in file
+ ULONGLONG m_llFileSize; // Size of the file
public:
CFlacStream(const WCHAR* wfn, CSource* pParent, HRESULT* phr);
- virtual ~CFlacStream();
+ virtual ~CFlacStream();
HRESULT FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len);
-
- HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
+
+ HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
HRESULT CheckMediaType(const CMediaType* pMediaType);
HRESULT GetMediaType(int iPosition, CMediaType* pmt);
- void UpdateFromMetadata (void* pBuffer);
- inline CFile* GetFile() { return &m_file; };
+ void UpdateFromMetadata(void* pBuffer);
+ inline CFile* GetFile()
+ {
+ return &m_file;
+ };
- bool m_bIsEOF;
+ bool m_bIsEOF;
};
diff --git a/src/filters/source/FlacSource/resource.h b/src/filters/source/FlacSource/resource.h
index 3507c6e74..6e541c0c4 100644
--- a/src/filters/source/FlacSource/resource.h
+++ b/src/filters/source/FlacSource/resource.h
@@ -3,7 +3,7 @@
// Used by dtsac3source.rc
// Next default values for new objects
-//
+//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
diff --git a/src/filters/source/FlacSource/stdafx.cpp b/src/filters/source/FlacSource/stdafx.cpp
index 396f14d73..4b148b3b2 100644
--- a/src/filters/source/FlacSource/stdafx.cpp
+++ b/src/filters/source/FlacSource/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
diff --git a/src/filters/source/FlacSource/stdafx.h b/src/filters/source/FlacSource/stdafx.h
index c35359c38..a9f666228 100644
--- a/src/filters/source/FlacSource/stdafx.h
+++ b/src/filters/source/FlacSource/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
diff --git a/src/filters/source/ShoutcastSource/ShoutcastSource.cpp b/src/filters/source/ShoutcastSource/ShoutcastSource.cpp
index 75bdf8d51..a2b8c5ec7 100644
--- a/src/filters/source/ShoutcastSource/ShoutcastSource.cpp
+++ b/src/filters/source/ShoutcastSource/ShoutcastSource.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
@@ -33,47 +33,47 @@
static const DWORD s_bitrate[2][16] =
{
- {1,8,16,24,32,40,48,56,64,80,96,112,128,144,160,0},
- {1,32,40,48,56,64,80,96,112,128,160,192,224,256,320,0}
+ {1, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0},
+ {1, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0}
};
static const DWORD s_freq[4][4] =
{
- {11025,12000,8000,0},
- {0,0,0,0},
- {22050,24000,16000,0},
- {44100,48000,32000,0}
+ {11025, 12000, 8000, 0},
+ {0, 0, 0, 0},
+ {22050, 24000, 16000, 0},
+ {44100, 48000, 32000, 0}
};
static const BYTE s_channels[4] =
{
- 2,2,2,1 // stereo, joint stereo, dual, mono
+ 2, 2, 2, 1 // stereo, joint stereo, dual, mono
};
typedef struct
{
- WORD sync;
- BYTE version;
- BYTE layer;
- DWORD bitrate;
- DWORD freq;
- BYTE channels;
- DWORD framesize;
-
- bool ExtractHeader(CSocket& socket)
- {
- BYTE buff[4];
- if(4 != socket.Receive(buff, 4, MSG_PEEK))
- return(false);
-
- sync = (buff[0]<<4)|(buff[1]>>4)|1;
- version = (buff[1]>>3)&3;
- layer = 4 - ((buff[1]>>1)&3);
- bitrate = s_bitrate[version&1][buff[2]>>4]*1000;
- freq = s_freq[version][(buff[2]>>2)&3];
- channels = s_channels[(buff[3]>>6)&3];
- framesize = freq ? ((((version&1)?144:72) * bitrate / freq) + ((buff[2]>>1)&1)) : 0;
-
- return(sync == 0xfff && layer == 3 && bitrate != 0 && freq != 0);
- }
+ WORD sync;
+ BYTE version;
+ BYTE layer;
+ DWORD bitrate;
+ DWORD freq;
+ BYTE channels;
+ DWORD framesize;
+
+ bool ExtractHeader(CSocket& socket)
+ {
+ BYTE buff[4];
+ if(4 != socket.Receive(buff, 4, MSG_PEEK))
+ return(false);
+
+ sync = (buff[0] << 4) | (buff[1] >> 4) | 1;
+ version = (buff[1] >> 3) & 3;
+ layer = 4 - ((buff[1] >> 1) & 3);
+ bitrate = s_bitrate[version&1][buff[2] >> 4] * 1000;
+ freq = s_freq[version][(buff[2] >> 2) & 3];
+ channels = s_channels[(buff[3] >> 6) & 3];
+ framesize = freq ? ((((version & 1) ? 144 : 72) * bitrate / freq) + ((buff[2] >> 1) & 1)) : 0;
+
+ return(sync == 0xfff && layer == 3 && bitrate != 0 && freq != 0);
+ }
} mp3hdr;
@@ -81,34 +81,34 @@ typedef struct
const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
{
- {&MEDIATYPE_Audio, &MEDIASUBTYPE_MP3},
+ {&MEDIATYPE_Audio, &MEDIASUBTYPE_MP3},
};
const AMOVIESETUP_PIN sudOpPin[] =
{
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
const AMOVIESETUP_FILTER sudFilter[] =
{
- {&__uuidof(CShoutcastSource), L"MPC - ShoutcastSource", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
+ {&__uuidof(CShoutcastSource), L"MPC - ShoutcastSource", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
};
CFactoryTemplate g_Templates[] =
{
- {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CShoutcastSource>, NULL, &sudFilter[0]}
+ {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CShoutcastSource>, NULL, &sudFilter[0]}
};
int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
- return AMovieDllRegisterServer2(TRUE);
+ return AMovieDllRegisterServer2(TRUE);
}
STDAPI DllUnregisterServer()
{
- return AMovieDllRegisterServer2(FALSE);
+ return AMovieDllRegisterServer2(FALSE);
}
#include "../../FilterApp.h"
@@ -116,24 +116,24 @@ STDAPI DllUnregisterServer()
class CShoutcastSourceApp : public CFilterApp
{
public:
- BOOL InitInstance()
- {
- if(!__super::InitInstance()) return FALSE;
-/*
- if(!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
- {
- AfxMessageBox(_T("AfxWinInit failed!"));
- return FALSE;
- }
-*/
- if(!AfxSocketInit(NULL))
- {
- AfxMessageBox(_T("AfxSocketInit failed!"));
- return FALSE;
- }
-
- return TRUE;
- }
+ BOOL InitInstance()
+ {
+ if(!__super::InitInstance()) return FALSE;
+ /*
+ if(!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
+ {
+ AfxMessageBox(_T("AfxWinInit failed!"));
+ return FALSE;
+ }
+ */
+ if(!AfxSocketInit(NULL))
+ {
+ AfxMessageBox(_T("AfxSocketInit failed!"));
+ return FALSE;
+ }
+
+ return TRUE;
+ }
};
CShoutcastSourceApp theApp;
@@ -145,10 +145,10 @@ CShoutcastSourceApp theApp;
//
CShoutcastSource::CShoutcastSource(LPUNKNOWN lpunk, HRESULT* phr)
- : CSource(NAME("CShoutcastSource"), lpunk, __uuidof(this))
+ : CSource(NAME("CShoutcastSource"), lpunk, __uuidof(this))
{
#ifndef REGISTER_FILTER
- AfxSocketInit();
+ AfxSocketInit();
#endif
}
@@ -160,96 +160,96 @@ STDMETHODIMP CShoutcastSource::NonDelegatingQueryInterface(REFIID riid, void** p
{
CheckPointer(ppv, E_POINTER);
- return
- QI(IFileSourceFilter)
- QI(IAMFilterMiscFlags)
- QI(IAMOpenProgress)
- QI2(IAMMediaContent)
- __super::NonDelegatingQueryInterface(riid, ppv);
+ return
+ QI(IFileSourceFilter)
+ QI(IAMFilterMiscFlags)
+ QI(IAMOpenProgress)
+ QI2(IAMMediaContent)
+ __super::NonDelegatingQueryInterface(riid, ppv);
}
// IFileSourceFilter
-STDMETHODIMP CShoutcastSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
+STDMETHODIMP CShoutcastSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
{
- if(GetPinCount() > 0)
- return VFW_E_ALREADY_CONNECTED;
+ if(GetPinCount() > 0)
+ return VFW_E_ALREADY_CONNECTED;
- HRESULT hr = E_OUTOFMEMORY;
+ HRESULT hr = E_OUTOFMEMORY;
- if(!(DNew CShoutcastStream(pszFileName, this, &hr)) || FAILED(hr))
- return hr;
+ if(!(DNew CShoutcastStream(pszFileName, this, &hr)) || FAILED(hr))
+ return hr;
- m_fn = pszFileName;
+ m_fn = pszFileName;
- return S_OK;
+ return S_OK;
}
STDMETHODIMP CShoutcastSource::GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
{
- if(!ppszFileName) return E_POINTER;
-
- if(!(*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength()+1)*sizeof(WCHAR))))
- return E_OUTOFMEMORY;
+ if(!ppszFileName) return E_POINTER;
+
+ if(!(*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength() + 1) * sizeof(WCHAR))))
+ return E_OUTOFMEMORY;
- wcscpy(*ppszFileName, m_fn);
+ wcscpy(*ppszFileName, m_fn);
- return S_OK;
+ return S_OK;
}
// IAMFilterMiscFlags
ULONG CShoutcastSource::GetMiscFlags()
{
- return AM_FILTER_MISC_FLAGS_IS_SOURCE;
+ return AM_FILTER_MISC_FLAGS_IS_SOURCE;
}
// IAMOpenProgress
STDMETHODIMP CShoutcastSource::QueryProgress(LONGLONG* pllTotal, LONGLONG* pllCurrent)
{
- if(m_iPins == 1)
- {
+ if(m_iPins == 1)
+ {
if(pllTotal) *pllTotal = 100;
- if(pllCurrent) *pllCurrent = (static_cast<CShoutcastStream*>(m_paStreams[0]))->GetBufferFullness();
- return S_OK;
- }
+ if(pllCurrent) *pllCurrent = (static_cast<CShoutcastStream*>(m_paStreams[0]))->GetBufferFullness();
+ return S_OK;
+ }
- return E_UNEXPECTED;
+ return E_UNEXPECTED;
}
STDMETHODIMP CShoutcastSource::AbortOperation()
{
- return E_NOTIMPL;
+ return E_NOTIMPL;
}
// IAMMediaContent
STDMETHODIMP CShoutcastSource::get_Title(BSTR* pbstrTitle)
{
- CheckPointer(pbstrTitle, E_POINTER);
+ CheckPointer(pbstrTitle, E_POINTER);
- if(m_iPins == 1)
- {
- *pbstrTitle = (static_cast<CShoutcastStream*>(m_paStreams[0]))->GetTitle().AllocSysString();
- return S_OK;
- }
+ if(m_iPins == 1)
+ {
+ *pbstrTitle = (static_cast<CShoutcastStream*>(m_paStreams[0]))->GetTitle().AllocSysString();
+ return S_OK;
+ }
- return E_UNEXPECTED;
+ return E_UNEXPECTED;
}
// CShoutcastStream
CShoutcastStream::CShoutcastStream(const WCHAR* wfn, CShoutcastSource* pParent, HRESULT* phr)
- : CSourceStream(NAME("ShoutcastStream"), phr, pParent, L"Output")
- , m_fBuffering(false)
+ : CSourceStream(NAME("ShoutcastStream"), phr, pParent, L"Output")
+ , m_fBuffering(false)
{
- ASSERT(phr);
+ ASSERT(phr);
- *phr = S_OK;
+ *phr = S_OK;
- CString fn(wfn);
- if(fn.Find(_T("://")) < 0) fn = _T("http://") + fn;
+ CString fn(wfn);
+ if(fn.Find(_T("://")) < 0) fn = _T("http://") + fn;
#if defined(REGISTER_FILTER) && defined(DEBUG)
//fn = _T("http://localhost:8000/");
@@ -257,37 +257,37 @@ CShoutcastStream::CShoutcastStream(const WCHAR* wfn, CShoutcastSource* pParent,
//fn = _T("http://218.145.30.106:11000"); // 128kbps korean
//fn = _T("http://65.206.46.110:8020"); // 96kbps
//fn = _T("http://64.236.34.72:80/stream/1003");
-fn = _T("http://64.236.34.72:80/stream/1011");
+ fn = _T("http://64.236.34.72:80/stream/1011");
//fn = _T("http://218.145.30.106:11000");
//fn = _T("http://radio.sluchaj.com:8000/radio.ogg"); // ogg
// http://www.oddsock.org/icecast2yp/ // more ogg via icecast2
#endif
- if(!m_url.CrackUrl(fn))
- {
- *phr = E_FAIL;
- return;
- }
+ if(!m_url.CrackUrl(fn))
+ {
+ *phr = E_FAIL;
+ return;
+ }
- if(m_url.GetUrlPathLength() == 0)
- m_url.SetUrlPath(_T("/"));
+ if(m_url.GetUrlPathLength() == 0)
+ m_url.SetUrlPath(_T("/"));
- if(m_url.GetPortNumber() == ATL_URL_INVALID_PORT_NUMBER)
- m_url.SetPortNumber(ATL_URL_DEFAULT_HTTP_PORT);
+ if(m_url.GetPortNumber() == ATL_URL_INVALID_PORT_NUMBER)
+ m_url.SetPortNumber(ATL_URL_DEFAULT_HTTP_PORT);
- if(m_url.GetScheme() != ATL_URL_SCHEME_HTTP)
- {
- *phr = E_FAIL;
- return;
- }
+ if(m_url.GetScheme() != ATL_URL_SCHEME_HTTP)
+ {
+ *phr = E_FAIL;
+ return;
+ }
- if(!m_socket.Create() || !m_socket.Connect(m_url))
- {
- *phr = E_FAIL;
- return;
- }
+ if(!m_socket.Create() || !m_socket.Connect(m_url))
+ {
+ *phr = E_FAIL;
+ return;
+ }
- m_socket.Close();
+ m_socket.Close();
}
CShoutcastStream::~CShoutcastStream()
@@ -296,23 +296,23 @@ CShoutcastStream::~CShoutcastStream()
void CShoutcastStream::EmptyBuffer()
{
- CAutoLock cAutoLock(&m_queue);
- m_queue.RemoveAll();
+ CAutoLock cAutoLock(&m_queue);
+ m_queue.RemoveAll();
}
LONGLONG CShoutcastStream::GetBufferFullness()
{
- CAutoLock cAutoLock(&m_queue);
- if(!m_fBuffering) return 100;
- if(m_queue.IsEmpty()) return 0;
- LONGLONG ret = 100i64*(m_queue.GetTail().rtStart - m_queue.GetHead().rtStart) / AVGBUFFERLENGTH;
- return(min(ret, 100));
+ CAutoLock cAutoLock(&m_queue);
+ if(!m_fBuffering) return 100;
+ if(m_queue.IsEmpty()) return 0;
+ LONGLONG ret = 100i64 * (m_queue.GetTail().rtStart - m_queue.GetHead().rtStart) / AVGBUFFERLENGTH;
+ return(min(ret, 100));
}
CString CShoutcastStream::GetTitle()
{
- CAutoLock cAutoLock(&m_queue);
- return(m_title);
+ CAutoLock cAutoLock(&m_queue);
+ return(m_title);
}
HRESULT CShoutcastStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties)
@@ -322,8 +322,8 @@ HRESULT CShoutcastStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROP
HRESULT hr = NOERROR;
- pProperties->cBuffers = BUFFERS;
- pProperties->cbBuffer = MAXFRAMESIZE;
+ pProperties->cBuffers = BUFFERS;
+ pProperties->cbBuffer = MAXFRAMESIZE;
ALLOCATOR_PROPERTIES Actual;
if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
@@ -336,65 +336,65 @@ HRESULT CShoutcastStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROP
HRESULT CShoutcastStream::FillBuffer(IMediaSample* pSample)
{
- HRESULT hr;
-
- BYTE* pData = NULL;
- if(FAILED(hr = pSample->GetPointer(&pData)) || !pData)
- return S_FALSE;
-
- do
- {
- // do we have to refill our buffer?
- {
- CAutoLock cAutoLock(&m_queue);
- if(!m_queue.IsEmpty() && m_queue.GetHead().rtStart < m_queue.GetTail().rtStart - MINBUFFERLENGTH)
- break; // nope, that's great
- }
-
- TRACE(_T("START BUFFERING\n"));
- m_fBuffering = true;
-
- while(1)
- {
- if(fExitThread) // playback stopped?
- return S_FALSE;
-
- Sleep(50);
-
- CAutoLock cAutoLock(&m_queue);
- if(!m_queue.IsEmpty() && m_queue.GetHead().rtStart < m_queue.GetTail().rtStart - AVGBUFFERLENGTH)
- break; // this is enough
- }
-
- pSample->SetDiscontinuity(TRUE);
-
- DeliverBeginFlush();
- DeliverEndFlush();
-
- DeliverNewSegment(0, ~0, 1.0);
-
- TRACE(_T("END BUFFERING\n"));
- m_fBuffering = false;
- }
- while(false);
-
- {
- CAutoLock cAutoLock(&m_queue);
- ASSERT(!m_queue.IsEmpty());
- if(!m_queue.IsEmpty())
- {
- mp3frame f = m_queue.RemoveHead();
- DWORD len = min(pSample->GetSize(), f.len);
- memcpy(pData, f.pData, len);
- pSample->SetActualDataLength(len);
- pSample->SetTime(&f.rtStart, &f.rtStop);
- m_title = f.title;
- }
- }
-
- pSample->SetSyncPoint(TRUE);
-
- return S_OK;
+ HRESULT hr;
+
+ BYTE* pData = NULL;
+ if(FAILED(hr = pSample->GetPointer(&pData)) || !pData)
+ return S_FALSE;
+
+ do
+ {
+ // do we have to refill our buffer?
+ {
+ CAutoLock cAutoLock(&m_queue);
+ if(!m_queue.IsEmpty() && m_queue.GetHead().rtStart < m_queue.GetTail().rtStart - MINBUFFERLENGTH)
+ break; // nope, that's great
+ }
+
+ TRACE(_T("START BUFFERING\n"));
+ m_fBuffering = true;
+
+ while(1)
+ {
+ if(fExitThread) // playback stopped?
+ return S_FALSE;
+
+ Sleep(50);
+
+ CAutoLock cAutoLock(&m_queue);
+ if(!m_queue.IsEmpty() && m_queue.GetHead().rtStart < m_queue.GetTail().rtStart - AVGBUFFERLENGTH)
+ break; // this is enough
+ }
+
+ pSample->SetDiscontinuity(TRUE);
+
+ DeliverBeginFlush();
+ DeliverEndFlush();
+
+ DeliverNewSegment(0, ~0, 1.0);
+
+ TRACE(_T("END BUFFERING\n"));
+ m_fBuffering = false;
+ }
+ while(false);
+
+ {
+ CAutoLock cAutoLock(&m_queue);
+ ASSERT(!m_queue.IsEmpty());
+ if(!m_queue.IsEmpty())
+ {
+ mp3frame f = m_queue.RemoveHead();
+ DWORD len = min(pSample->GetSize(), f.len);
+ memcpy(pData, f.pData, len);
+ pSample->SetActualDataLength(len);
+ pSample->SetTime(&f.rtStart, &f.rtStop);
+ m_title = f.title;
+ }
+ }
+
+ pSample->SetSyncPoint(TRUE);
+
+ return S_OK;
}
HRESULT CShoutcastStream::GetMediaType(int iPosition, CMediaType* pmt)
@@ -408,286 +408,290 @@ HRESULT CShoutcastStream::GetMediaType(int iPosition, CMediaType* pmt)
pmt->SetSubtype(&MEDIASUBTYPE_MP3);
pmt->SetFormatType(&FORMAT_WaveFormatEx);
- WAVEFORMATEX* wfe = (WAVEFORMATEX*)pmt->AllocFormatBuffer(sizeof(WAVEFORMATEX));
- memset(wfe, 0, sizeof(WAVEFORMATEX));
- wfe->wFormatTag = (WORD)MEDIASUBTYPE_MP3.Data1;
- wfe->nChannels = (WORD)m_socket.m_channels;
- wfe->nSamplesPerSec = m_socket.m_freq;
- wfe->nAvgBytesPerSec = m_socket.m_bitrate/8;
- wfe->nBlockAlign = 1;
- wfe->wBitsPerSample = 0;
+ WAVEFORMATEX* wfe = (WAVEFORMATEX*)pmt->AllocFormatBuffer(sizeof(WAVEFORMATEX));
+ memset(wfe, 0, sizeof(WAVEFORMATEX));
+ wfe->wFormatTag = (WORD)MEDIASUBTYPE_MP3.Data1;
+ wfe->nChannels = (WORD)m_socket.m_channels;
+ wfe->nSamplesPerSec = m_socket.m_freq;
+ wfe->nAvgBytesPerSec = m_socket.m_bitrate / 8;
+ wfe->nBlockAlign = 1;
+ wfe->wBitsPerSample = 0;
return NOERROR;
}
HRESULT CShoutcastStream::CheckMediaType(const CMediaType* pmt)
{
- if(pmt->majortype == MEDIATYPE_Audio
- && pmt->subtype == MEDIASUBTYPE_MP3
- && pmt->formattype == FORMAT_WaveFormatEx) return S_OK;
+ if(pmt->majortype == MEDIATYPE_Audio
+ && pmt->subtype == MEDIASUBTYPE_MP3
+ && pmt->formattype == FORMAT_WaveFormatEx) return S_OK;
- return E_INVALIDARG;
+ return E_INVALIDARG;
}
static UINT SocketThreadProc(LPVOID pParam)
{
- return (static_cast<CShoutcastStream*>(pParam))->SocketThreadProc();
+ return (static_cast<CShoutcastStream*>(pParam))->SocketThreadProc();
}
UINT CShoutcastStream::SocketThreadProc()
{
- fExitThread = false;
+ fExitThread = false;
- SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
- AfxSocketInit();
+ AfxSocketInit();
- CAutoVectorPtr<BYTE> pData;
- if(!m_socket.Create() || !m_socket.Connect(m_url)
- || !pData.Allocate(max(m_socket.m_metaint, MAXFRAMESIZE)))
- {
- m_socket.Close();
- return 1;
- }
+ CAutoVectorPtr<BYTE> pData;
+ if(!m_socket.Create() || !m_socket.Connect(m_url)
+ || !pData.Allocate(max(m_socket.m_metaint, MAXFRAMESIZE)))
+ {
+ m_socket.Close();
+ return 1;
+ }
- REFERENCE_TIME m_rtSampleTime = 0;
-
- while(!fExitThread)
- {
- int len = MAXFRAMESIZE;
- len = m_socket.Receive(pData, len);
- if(len <= 0) break;
+ REFERENCE_TIME m_rtSampleTime = 0;
- mp3frame f(len);
- memcpy(f.pData, pData, len);
- f.rtStop = (f.rtStart = m_rtSampleTime) + (10000000i64 * len * 8/m_socket.m_bitrate);
- m_rtSampleTime = f.rtStop;
- f.title = m_socket.m_title;
- if(f.title.IsEmpty()) f.title = m_socket.m_url;
+ while(!fExitThread)
+ {
+ int len = MAXFRAMESIZE;
+ len = m_socket.Receive(pData, len);
+ if(len <= 0) break;
- CAutoLock cAutoLock(&m_queue);
- m_queue.AddTail(f);
- }
+ mp3frame f(len);
+ memcpy(f.pData, pData, len);
+ f.rtStop = (f.rtStart = m_rtSampleTime) + (10000000i64 * len * 8 / m_socket.m_bitrate);
+ m_rtSampleTime = f.rtStop;
+ f.title = m_socket.m_title;
+ if(f.title.IsEmpty()) f.title = m_socket.m_url;
- m_socket.Close();
+ CAutoLock cAutoLock(&m_queue);
+ m_queue.AddTail(f);
+ }
- return 0;
+ m_socket.Close();
+
+ return 0;
}
HRESULT CShoutcastStream::OnThreadCreate()
{
- EmptyBuffer();
+ EmptyBuffer();
- fExitThread = true;
- m_hSocketThread = AfxBeginThread(::SocketThreadProc, this)->m_hThread;
- while(fExitThread) Sleep(10);
+ fExitThread = true;
+ m_hSocketThread = AfxBeginThread(::SocketThreadProc, this)->m_hThread;
+ while(fExitThread) Sleep(10);
- return NOERROR;
+ return NOERROR;
}
HRESULT CShoutcastStream::OnThreadDestroy()
{
- EmptyBuffer();
-
- fExitThread = true;
- m_socket.CancelBlockingCall();
- WaitForSingleObject(m_hSocketThread, -1);
+ EmptyBuffer();
- return NOERROR;
+ fExitThread = true;
+ m_socket.CancelBlockingCall();
+ WaitForSingleObject(m_hSocketThread, -1);
+
+ return NOERROR;
}
HRESULT CShoutcastStream::Inactive()
{
- fExitThread = true;
- return __super::Inactive();
+ fExitThread = true;
+ return __super::Inactive();
}
//
int CShoutcastStream::CShoutcastSocket::Receive(void* lpBuf, int nBufLen, int nFlags)
{
- if(nFlags&MSG_PEEK)
- return __super::Receive(lpBuf, nBufLen, nFlags);
-
- if(m_metaint > 0 && m_nBytesRead + nBufLen > m_metaint)
- nBufLen = m_metaint - m_nBytesRead;
-
- int len = __super::Receive(lpBuf, nBufLen, nFlags);
- if(len <= 0) return len;
-
- if((m_nBytesRead += len) == m_metaint)
- {
- m_nBytesRead = 0;
-
- static BYTE buff[255*16], b = 0;
- memset(buff, 0, sizeof(buff));
- if(1 == __super::Receive(&b, 1) && b && b*16 == __super::Receive(buff, b*16))
- {
- CStringA str = (LPCSTR)buff;
-
- TRACE(_T("Metainfo: %s\n"), CString(str));
-
- CStringA title("StreamTitle='"), url("StreamUrl='");
-
- int i = str.Find(title);
- if(i >= 0)
- {
- i += title.GetLength();
- int j = str.Find('\'', i);
- if(j > i) m_title = str.Mid(i, j - i);
- }
- else
- {
- TRACE(_T("!!!!!!!!!Missing StreamTitle!!!!!!!!!\n"));
- }
-
- i = str.Find(url);
- if(i >= 0)
- {
- i += url.GetLength();
- int j = str.Find('\'', i);
- if(j > i) m_url = str.Mid(i, j - i);
- }
- }
- }
- else if(m_metaint > 0)
- {
- char* p = (char*)lpBuf;
- char* p0 = p;
- char* pend = p + len - 13;
- for(; p < pend; p++)
- {
- if(strncmp(p, "StreamTitle='", 13))
- continue;
-
-TRACE(_T("!!!!!!!!!StreamTitle found inside mp3 data!!!!!!!!! offset=%d\n"), p - p0);
-TRACE(_T("resyncing...\n"));
- while(p-- > p0)
- {
- if((BYTE)*p >= 0x20)
- continue;
-
-TRACE(_T("found possible length byte: %d, skipping %d bytes\n"), *p, 1 + *p*16);
- p += 1 + *p*16;
- len = (p0 + len) - p;
-TRACE(_T("returning the remaining bytes in the packet: %d\n"), len);
- if(len <= 0)
- {
-TRACE(_T("nothing to return, reading a bit more in\n"));
- if(len < 0) __super::Receive(lpBuf, -len, nFlags);
-
- int len = __super::Receive(lpBuf, nBufLen, nFlags);
- if(len <= 0) return len;
- }
-
- m_nBytesRead = len;
- memcpy(lpBuf, p, len);
-
- break;
- }
-
- break;
- }
- }
-
- return len;
+ if(nFlags & MSG_PEEK)
+ return __super::Receive(lpBuf, nBufLen, nFlags);
+
+ if(m_metaint > 0 && m_nBytesRead + nBufLen > m_metaint)
+ nBufLen = m_metaint - m_nBytesRead;
+
+ int len = __super::Receive(lpBuf, nBufLen, nFlags);
+ if(len <= 0) return len;
+
+ if((m_nBytesRead += len) == m_metaint)
+ {
+ m_nBytesRead = 0;
+
+ static BYTE buff[255*16], b = 0;
+ memset(buff, 0, sizeof(buff));
+ if(1 == __super::Receive(&b, 1) && b && b * 16 == __super::Receive(buff, b * 16))
+ {
+ CStringA str = (LPCSTR)buff;
+
+ TRACE(_T("Metainfo: %s\n"), CString(str));
+
+ CStringA title("StreamTitle='"), url("StreamUrl='");
+
+ int i = str.Find(title);
+ if(i >= 0)
+ {
+ i += title.GetLength();
+ int j = str.Find('\'', i);
+ if(j > i) m_title = str.Mid(i, j - i);
+ }
+ else
+ {
+ TRACE(_T("!!!!!!!!!Missing StreamTitle!!!!!!!!!\n"));
+ }
+
+ i = str.Find(url);
+ if(i >= 0)
+ {
+ i += url.GetLength();
+ int j = str.Find('\'', i);
+ if(j > i) m_url = str.Mid(i, j - i);
+ }
+ }
+ }
+ else if(m_metaint > 0)
+ {
+ char* p = (char*)lpBuf;
+ char* p0 = p;
+ char* pend = p + len - 13;
+ for(; p < pend; p++)
+ {
+ if(strncmp(p, "StreamTitle='", 13))
+ continue;
+
+ TRACE(_T("!!!!!!!!!StreamTitle found inside mp3 data!!!!!!!!! offset=%d\n"), p - p0);
+ TRACE(_T("resyncing...\n"));
+ while(p-- > p0)
+ {
+ if((BYTE)*p >= 0x20)
+ continue;
+
+ TRACE(_T("found possible length byte: %d, skipping %d bytes\n"), *p, 1 + *p * 16);
+ p += 1 + *p * 16;
+ len = (p0 + len) - p;
+ TRACE(_T("returning the remaining bytes in the packet: %d\n"), len);
+ if(len <= 0)
+ {
+ TRACE(_T("nothing to return, reading a bit more in\n"));
+ if(len < 0) __super::Receive(lpBuf, -len, nFlags);
+
+ int len = __super::Receive(lpBuf, nBufLen, nFlags);
+ if(len <= 0) return len;
+ }
+
+ m_nBytesRead = len;
+ memcpy(lpBuf, p, len);
+
+ break;
+ }
+
+ break;
+ }
+ }
+
+ return len;
}
bool CShoutcastStream::CShoutcastSocket::Connect(CUrl& url)
{
- if(!__super::Connect(url.GetHostName(), url.GetPortNumber()))
- return(false);
-
- CStringA str;
- str.Format(
- "GET %s HTTP/1.0\r\n"
- "Icy-MetaData:1\r\n"
- "User-Agent: shoutcastsource\r\n"
- "Host: %s\r\n"
- "Accept: */*\r\n"
- "Connection: Keep-Alive\r\n"
- "\r\n", CStringA(url.GetUrlPath()), CStringA(url.GetHostName()));
-
- bool fOK = false;
- bool fTryAgain = false;
- int metaint = 0;
-
- do
- {
- int len = Send((BYTE*)(LPCSTR)str, str.GetLength());
-
- m_nBytesRead = 0;
- m_metaint = metaint = 0;
- m_bitrate = 0;
-
- str.Empty();
- BYTE cur = 0, prev = 0;
- while(Receive(&cur, 1) == 1 && cur && !(cur == '\n' && prev == '\n'))
- {
- if(cur == '\r')
- continue;
-
- if(cur == '\n')
- {
- str.MakeLower();
- if(str.Find("icy 200 ok") >= 0) fOK = true;
- else if(1 == sscanf(str, "icy-br:%d", &m_bitrate)) m_bitrate *= 1000;
- else if(1 == sscanf(str, "icy-metaint:%d", &metaint)) metaint = metaint;
- str.Empty();
- }
- else
- {
- str += cur;
- }
-
- prev = cur;
- cur = 0;
- }
-
- if(!fOK && GetLastError() == WSAECONNRESET && !fTryAgain)
- {
- str.Format(
- "GET %s HTTP/1.0\r\n"
- "Icy-MetaData:1\r\n"
- "Host: %s\r\n"
- "Accept: */*\r\n"
- "Connection: Keep-Alive\r\n"
- "\r\n", CStringA(url.GetUrlPath()), CStringA(url.GetHostName()));
-
- fTryAgain = true;
- }
- else
- {
- fTryAgain = false;
- }
- }
- while(fTryAgain);
-
- if(!fOK || m_bitrate == 0) {Close(); return(false);}
-
- m_metaint = metaint;
- m_nBytesRead = 0;
-
- return(FindSync());
+ if(!__super::Connect(url.GetHostName(), url.GetPortNumber()))
+ return(false);
+
+ CStringA str;
+ str.Format(
+ "GET %s HTTP/1.0\r\n"
+ "Icy-MetaData:1\r\n"
+ "User-Agent: shoutcastsource\r\n"
+ "Host: %s\r\n"
+ "Accept: */*\r\n"
+ "Connection: Keep-Alive\r\n"
+ "\r\n", CStringA(url.GetUrlPath()), CStringA(url.GetHostName()));
+
+ bool fOK = false;
+ bool fTryAgain = false;
+ int metaint = 0;
+
+ do
+ {
+ int len = Send((BYTE*)(LPCSTR)str, str.GetLength());
+
+ m_nBytesRead = 0;
+ m_metaint = metaint = 0;
+ m_bitrate = 0;
+
+ str.Empty();
+ BYTE cur = 0, prev = 0;
+ while(Receive(&cur, 1) == 1 && cur && !(cur == '\n' && prev == '\n'))
+ {
+ if(cur == '\r')
+ continue;
+
+ if(cur == '\n')
+ {
+ str.MakeLower();
+ if(str.Find("icy 200 ok") >= 0) fOK = true;
+ else if(1 == sscanf(str, "icy-br:%d", &m_bitrate)) m_bitrate *= 1000;
+ else if(1 == sscanf(str, "icy-metaint:%d", &metaint)) metaint = metaint;
+ str.Empty();
+ }
+ else
+ {
+ str += cur;
+ }
+
+ prev = cur;
+ cur = 0;
+ }
+
+ if(!fOK && GetLastError() == WSAECONNRESET && !fTryAgain)
+ {
+ str.Format(
+ "GET %s HTTP/1.0\r\n"
+ "Icy-MetaData:1\r\n"
+ "Host: %s\r\n"
+ "Accept: */*\r\n"
+ "Connection: Keep-Alive\r\n"
+ "\r\n", CStringA(url.GetUrlPath()), CStringA(url.GetHostName()));
+
+ fTryAgain = true;
+ }
+ else
+ {
+ fTryAgain = false;
+ }
+ }
+ while(fTryAgain);
+
+ if(!fOK || m_bitrate == 0)
+ {
+ Close();
+ return(false);
+ }
+
+ m_metaint = metaint;
+ m_nBytesRead = 0;
+
+ return(FindSync());
}
bool CShoutcastStream::CShoutcastSocket::FindSync()
{
- m_freq = -1;
- m_channels = -1;
-
- BYTE b;
- for(int i = MAXFRAMESIZE; i > 0; i--, Receive(&b, 1))
- {
- mp3hdr h;
- if(h.ExtractHeader(*this) && m_bitrate == h.bitrate)
- {
- if(h.bitrate > 1) m_bitrate = h.bitrate;
- m_freq = h.freq;
- m_channels = h.channels;
- return(true);
- }
- }
-
- return(false);
+ m_freq = -1;
+ m_channels = -1;
+
+ BYTE b;
+ for(int i = MAXFRAMESIZE; i > 0; i--, Receive(&b, 1))
+ {
+ mp3hdr h;
+ if(h.ExtractHeader(*this) && m_bitrate == h.bitrate)
+ {
+ if(h.bitrate > 1) m_bitrate = h.bitrate;
+ m_freq = h.freq;
+ m_channels = h.channels;
+ return(true);
+ }
+ }
+
+ return(false);
}
diff --git a/src/filters/source/ShoutcastSource/ShoutcastSource.h b/src/filters/source/ShoutcastSource/ShoutcastSource.h
index ab45dbf4f..080b6f198 100644
--- a/src/filters/source/ShoutcastSource/ShoutcastSource.h
+++ b/src/filters/source/ShoutcastSource/ShoutcastSource.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
@@ -29,118 +29,182 @@
[uuid("68F540E9-766F-44d2-AB07-E26CC6D27A79")]
class CShoutcastSource
- : public CSource
- , public IFileSourceFilter
- , public IAMFilterMiscFlags
- , public IAMOpenProgress
- , public IAMMediaContent
+ : public CSource
+ , public IFileSourceFilter
+ , public IAMFilterMiscFlags
+ , public IAMOpenProgress
+ , public IAMMediaContent
{
- CStringW m_fn;
+ CStringW m_fn;
public:
- CShoutcastSource(LPUNKNOWN lpunk, HRESULT* phr);
- virtual ~CShoutcastSource();
+ CShoutcastSource(LPUNKNOWN lpunk, HRESULT* phr);
+ virtual ~CShoutcastSource();
- DECLARE_IUNKNOWN;
+ DECLARE_IUNKNOWN;
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
- // IFileSourceFilter
- STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt);
- STDMETHODIMP GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt);
+ // IFileSourceFilter
+ STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt);
+ STDMETHODIMP GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt);
- // IAMFilterMiscFlags
- STDMETHODIMP_(ULONG) GetMiscFlags();
+ // IAMFilterMiscFlags
+ STDMETHODIMP_(ULONG) GetMiscFlags();
- // IAMOpenProgress
+ // IAMOpenProgress
STDMETHODIMP QueryProgress(LONGLONG* pllTotal, LONGLONG* pllCurrent);
STDMETHODIMP AbortOperation();
- // IAMMediaContent
- STDMETHODIMP GetTypeInfoCount(UINT* pctinfo) {return E_NOTIMPL;}
- STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo) {return E_NOTIMPL;}
- STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid) {return E_NOTIMPL;}
- STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr) {return E_NOTIMPL;}
- STDMETHODIMP get_AuthorName(BSTR* pbstrAuthorName) {return E_NOTIMPL;}
- STDMETHODIMP get_Title(BSTR* pbstrTitle);
- STDMETHODIMP get_Rating(BSTR* pbstrRating) {return E_NOTIMPL;}
- STDMETHODIMP get_Description(BSTR* pbstrDescription) {return E_NOTIMPL;}
- STDMETHODIMP get_Copyright(BSTR* pbstrCopyright) {return E_NOTIMPL;}
- STDMETHODIMP get_BaseURL(BSTR* pbstrBaseURL) {return E_NOTIMPL;}
- STDMETHODIMP get_LogoURL(BSTR* pbstrLogoURL) {return E_NOTIMPL;}
- STDMETHODIMP get_LogoIconURL(BSTR* pbstrLogoURL) {return E_NOTIMPL;}
- STDMETHODIMP get_WatermarkURL(BSTR* pbstrWatermarkURL) {return E_NOTIMPL;}
- STDMETHODIMP get_MoreInfoURL(BSTR* pbstrMoreInfoURL) {return E_NOTIMPL;}
- STDMETHODIMP get_MoreInfoBannerImage(BSTR* pbstrMoreInfoBannerImage) {return E_NOTIMPL;}
- STDMETHODIMP get_MoreInfoBannerURL(BSTR* pbstrMoreInfoBannerURL) {return E_NOTIMPL;}
- STDMETHODIMP get_MoreInfoText(BSTR* pbstrMoreInfoText) {return E_NOTIMPL;}
+ // IAMMediaContent
+ STDMETHODIMP GetTypeInfoCount(UINT* pctinfo)
+ {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
+ {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid)
+ {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr)
+ {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_AuthorName(BSTR* pbstrAuthorName)
+ {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_Title(BSTR* pbstrTitle);
+ STDMETHODIMP get_Rating(BSTR* pbstrRating)
+ {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_Description(BSTR* pbstrDescription)
+ {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_Copyright(BSTR* pbstrCopyright)
+ {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_BaseURL(BSTR* pbstrBaseURL)
+ {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_LogoURL(BSTR* pbstrLogoURL)
+ {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_LogoIconURL(BSTR* pbstrLogoURL)
+ {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_WatermarkURL(BSTR* pbstrWatermarkURL)
+ {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_MoreInfoURL(BSTR* pbstrMoreInfoURL)
+ {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_MoreInfoBannerImage(BSTR* pbstrMoreInfoBannerImage)
+ {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_MoreInfoBannerURL(BSTR* pbstrMoreInfoBannerURL)
+ {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_MoreInfoText(BSTR* pbstrMoreInfoText)
+ {
+ return E_NOTIMPL;
+ }
};
class CShoutcastStream : public CSourceStream
{
- class mp3frame
- {
- public:
- DWORD len;
- BYTE* pData;
- REFERENCE_TIME rtStart, rtStop;
- CString title;
- mp3frame(DWORD len = 0) {pData = (this->len = len) ? DNew BYTE[len] : NULL; rtStart = rtStop = 0;}
- mp3frame(const mp3frame& f) {*this = f;}
- ~mp3frame() {delete pData;}
- void operator = (const mp3frame& f)
- {
- len = f.len;
- pData = f.pData;
- rtStart = f.rtStart;
- rtStop = f.rtStop;
- title = f.title;
- ((mp3frame*)&f)->pData = NULL;
- }
- };
-
- class mp3queue : public CAtlList<mp3frame>, public CCritSec {} m_queue;
-
- class CShoutcastSocket : public CSocket
- {
- DWORD m_nBytesRead;
-
- public:
- CShoutcastSocket() {m_metaint = m_bitrate = m_freq = m_channels = 0;}
- int Receive(void* lpBuf, int nBufLen, int nFlags = 0);
-
- DWORD m_metaint, m_bitrate, m_freq, m_channels;
- CString m_title, m_url;
- bool Connect(CUrl& url);
- bool FindSync();
- } m_socket;
-
- HANDLE m_hSocketThread;
-
- CUrl m_url;
-
- bool m_fBuffering;
- CString m_title;
+ class mp3frame
+ {
+ public:
+ DWORD len;
+ BYTE* pData;
+ REFERENCE_TIME rtStart, rtStop;
+ CString title;
+ mp3frame(DWORD len = 0)
+ {
+ pData = (this->len = len) ? DNew BYTE[len] : NULL;
+ rtStart = rtStop = 0;
+ }
+ mp3frame(const mp3frame& f)
+ {
+ *this = f;
+ }
+ ~mp3frame()
+ {
+ delete pData;
+ }
+ void operator = (const mp3frame& f)
+ {
+ len = f.len;
+ pData = f.pData;
+ rtStart = f.rtStart;
+ rtStop = f.rtStop;
+ title = f.title;
+ ((mp3frame*)&f)->pData = NULL;
+ }
+ };
+
+ class mp3queue : public CAtlList<mp3frame>, public CCritSec {} m_queue;
+
+ class CShoutcastSocket : public CSocket
+ {
+ DWORD m_nBytesRead;
+
+ public:
+ CShoutcastSocket()
+ {
+ m_metaint = m_bitrate = m_freq = m_channels = 0;
+ }
+ int Receive(void* lpBuf, int nBufLen, int nFlags = 0);
+
+ DWORD m_metaint, m_bitrate, m_freq, m_channels;
+ CString m_title, m_url;
+ bool Connect(CUrl& url);
+ bool FindSync();
+ } m_socket;
+
+ HANDLE m_hSocketThread;
+
+ CUrl m_url;
+
+ bool m_fBuffering;
+ CString m_title;
public:
CShoutcastStream(const WCHAR* wfn, CShoutcastSource* pParent, HRESULT* phr);
- virtual ~CShoutcastStream();
+ virtual ~CShoutcastStream();
- bool fExitThread;
- UINT SocketThreadProc();
+ bool fExitThread;
+ UINT SocketThreadProc();
- void EmptyBuffer();
- LONGLONG GetBufferFullness();
- CString GetTitle();
+ void EmptyBuffer();
+ LONGLONG GetBufferFullness();
+ CString GetTitle();
HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
HRESULT FillBuffer(IMediaSample* pSample);
HRESULT CheckMediaType(const CMediaType* pMediaType);
HRESULT GetMediaType(int iPosition, CMediaType* pmt);
- STDMETHODIMP Notify(IBaseFilter* pSender, Quality q) {return E_NOTIMPL;}
+ STDMETHODIMP Notify(IBaseFilter* pSender, Quality q)
+ {
+ return E_NOTIMPL;
+ }
HRESULT OnThreadCreate();
HRESULT OnThreadDestroy();
- HRESULT Inactive();
+ HRESULT Inactive();
HRESULT Pause();
};
diff --git a/src/filters/source/ShoutcastSource/resource.h b/src/filters/source/ShoutcastSource/resource.h
index ae3ca9687..8a12dbf0d 100644
--- a/src/filters/source/ShoutcastSource/resource.h
+++ b/src/filters/source/ShoutcastSource/resource.h
@@ -3,7 +3,7 @@
// Used by shoutcastsource.rc
// Next default values for new objects
-//
+//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
diff --git a/src/filters/source/ShoutcastSource/stdafx.cpp b/src/filters/source/ShoutcastSource/stdafx.cpp
index 8905f2db5..0385cc615 100644
--- a/src/filters/source/ShoutcastSource/stdafx.cpp
+++ b/src/filters/source/ShoutcastSource/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
diff --git a/src/filters/source/ShoutcastSource/stdafx.h b/src/filters/source/ShoutcastSource/stdafx.h
index c35359c38..a9f666228 100644
--- a/src/filters/source/ShoutcastSource/stdafx.h
+++ b/src/filters/source/ShoutcastSource/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
diff --git a/src/filters/source/SubtitleSource/SubtitleSource.cpp b/src/filters/source/SubtitleSource/SubtitleSource.cpp
index 0bddf17a8..db9b9aa4d 100644
--- a/src/filters/source/SubtitleSource/SubtitleSource.cpp
+++ b/src/filters/source/SubtitleSource/SubtitleSource.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
@@ -34,87 +34,87 @@ static int _ATPF = 400000;
const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
{
- {&MEDIATYPE_Subtitle, &MEDIASUBTYPE_NULL},
- {&MEDIATYPE_Text, &MEDIASUBTYPE_NULL},
- {&MEDIATYPE_Video, &MEDIASUBTYPE_RGB32},
+ {&MEDIATYPE_Subtitle, &MEDIASUBTYPE_NULL},
+ {&MEDIATYPE_Text, &MEDIASUBTYPE_NULL},
+ {&MEDIATYPE_Video, &MEDIASUBTYPE_RGB32},
};
const AMOVIESETUP_PIN sudOpPin[] =
{
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut},
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut},
};
const AMOVIESETUP_FILTER sudFilter[] =
{
- {&__uuidof(CSubtitleSourceASCII), L"MPC - SubtitleSource (S_TEXT/ASCII)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
- {&__uuidof(CSubtitleSourceUTF8), L"MPC - SubtitleSource (S_TEXT/UTF8)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
- {&__uuidof(CSubtitleSourceSSA), L"MPC - SubtitleSource (S_TEXT/SSA)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
- {&__uuidof(CSubtitleSourceASS), L"MPC - SubtitleSource (S_TEXT/ASS)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
- {&__uuidof(CSubtitleSourceUSF), L"MPC - SubtitleSource (S_TEXT/USF)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
- {&__uuidof(CSubtitleSourcePreview), L"MPC - SubtitleSource (Preview)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
- {&__uuidof(CSubtitleSourceARGB), L"MPC - SubtitleSource (ARGB)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
+ {&__uuidof(CSubtitleSourceASCII), L"MPC - SubtitleSource (S_TEXT/ASCII)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
+ {&__uuidof(CSubtitleSourceUTF8), L"MPC - SubtitleSource (S_TEXT/UTF8)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
+ {&__uuidof(CSubtitleSourceSSA), L"MPC - SubtitleSource (S_TEXT/SSA)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
+ {&__uuidof(CSubtitleSourceASS), L"MPC - SubtitleSource (S_TEXT/ASS)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
+ {&__uuidof(CSubtitleSourceUSF), L"MPC - SubtitleSource (S_TEXT/USF)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
+ {&__uuidof(CSubtitleSourcePreview), L"MPC - SubtitleSource (Preview)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
+ {&__uuidof(CSubtitleSourceARGB), L"MPC - SubtitleSource (ARGB)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
};
CFactoryTemplate g_Templates[] =
{
- {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CSubtitleSourceASCII>, NULL, &sudFilter[0]},
- {sudFilter[1].strName, sudFilter[1].clsID, CreateInstance<CSubtitleSourceUTF8>, NULL, &sudFilter[1]},
- {sudFilter[2].strName, sudFilter[2].clsID, CreateInstance<CSubtitleSourceSSA>, NULL, &sudFilter[2]},
- {sudFilter[3].strName, sudFilter[3].clsID, CreateInstance<CSubtitleSourceASS>, NULL, &sudFilter[3]},
+ {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CSubtitleSourceASCII>, NULL, &sudFilter[0]},
+ {sudFilter[1].strName, sudFilter[1].clsID, CreateInstance<CSubtitleSourceUTF8>, NULL, &sudFilter[1]},
+ {sudFilter[2].strName, sudFilter[2].clsID, CreateInstance<CSubtitleSourceSSA>, NULL, &sudFilter[2]},
+ {sudFilter[3].strName, sudFilter[3].clsID, CreateInstance<CSubtitleSourceASS>, NULL, &sudFilter[3]},
// {sudFilter[4].strName, sudFilter[4].clsID, CreateInstance<CSubtitleSourceUSF>, NULL, &sudFilter[4]},
- {sudFilter[5].strName, sudFilter[5].clsID, CreateInstance<CSubtitleSourcePreview>, NULL, &sudFilter[5]},
- {sudFilter[6].strName, sudFilter[6].clsID, CreateInstance<CSubtitleSourceARGB>, NULL, &sudFilter[6]},
+ {sudFilter[5].strName, sudFilter[5].clsID, CreateInstance<CSubtitleSourcePreview>, NULL, &sudFilter[5]},
+ {sudFilter[6].strName, sudFilter[6].clsID, CreateInstance<CSubtitleSourceARGB>, NULL, &sudFilter[6]},
};
int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
-/*
- CString clsid = CStringFromGUID(__uuidof(CSubtitleSourcePreview));
+ /*
+ CString clsid = CStringFromGUID(__uuidof(CSubtitleSourcePreview));
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".sub"),
- _T("Source Filter"), clsid);
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".sub"),
+ _T("Source Filter"), clsid);
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".srt"),
- _T("Source Filter"), clsid);
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".srt"),
+ _T("Source Filter"), clsid);
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".smi"),
- _T("Source Filter"), clsid);
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".smi"),
+ _T("Source Filter"), clsid);
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".ssa"),
- _T("Source Filter"), clsid);
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".ssa"),
+ _T("Source Filter"), clsid);
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".ass"),
- _T("Source Filter"), clsid);
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".ass"),
+ _T("Source Filter"), clsid);
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".xss"),
- _T("Source Filter"), clsid);
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".xss"),
+ _T("Source Filter"), clsid);
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".usf"),
- _T("Source Filter"), clsid);
-*/
- return AMovieDllRegisterServer2(TRUE);
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".usf"),
+ _T("Source Filter"), clsid);
+ */
+ return AMovieDllRegisterServer2(TRUE);
}
STDAPI DllUnregisterServer()
{
- DeleteRegKey(_T("Media Type\\Extensions"), _T(".sub"));
- DeleteRegKey(_T("Media Type\\Extensions"), _T(".srt"));
- DeleteRegKey(_T("Media Type\\Extensions"), _T(".smi"));
- DeleteRegKey(_T("Media Type\\Extensions"), _T(".ssa"));
- DeleteRegKey(_T("Media Type\\Extensions"), _T(".ass"));
- DeleteRegKey(_T("Media Type\\Extensions"), _T(".xss"));
- DeleteRegKey(_T("Media Type\\Extensions"), _T(".usf"));
-/**/
- return AMovieDllRegisterServer2(FALSE);
+ DeleteRegKey(_T("Media Type\\Extensions"), _T(".sub"));
+ DeleteRegKey(_T("Media Type\\Extensions"), _T(".srt"));
+ DeleteRegKey(_T("Media Type\\Extensions"), _T(".smi"));
+ DeleteRegKey(_T("Media Type\\Extensions"), _T(".ssa"));
+ DeleteRegKey(_T("Media Type\\Extensions"), _T(".ass"));
+ DeleteRegKey(_T("Media Type\\Extensions"), _T(".xss"));
+ DeleteRegKey(_T("Media Type\\Extensions"), _T(".usf"));
+ /**/
+ return AMovieDllRegisterServer2(FALSE);
}
#include "../../FilterApp.h"
@@ -122,20 +122,20 @@ STDAPI DllUnregisterServer()
class CSubtitleSourceApp : public CFilterApp
{
public:
- BOOL InitInstance()
- {
- if(!__super::InitInstance()) return FALSE;
-
- _WIDTH = GetProfileInt(_T("SubtitleSource"), _T("w"), 640);
- _HEIGHT = GetProfileInt(_T("SubtitleSource"), _T("h"), 480);
- _ATPF = GetProfileInt(_T("SubtitleSource"), _T("atpf"), 400000);
- if(_ATPF <= 0) _ATPF = 400000;
- WriteProfileInt(_T("SubtitleSource"), _T("w"), _WIDTH);
- WriteProfileInt(_T("SubtitleSource"), _T("h"), _HEIGHT);
- WriteProfileInt(_T("SubtitleSource"), _T("atpf"), _ATPF);
-
- return TRUE;
- }
+ BOOL InitInstance()
+ {
+ if(!__super::InitInstance()) return FALSE;
+
+ _WIDTH = GetProfileInt(_T("SubtitleSource"), _T("w"), 640);
+ _HEIGHT = GetProfileInt(_T("SubtitleSource"), _T("h"), 480);
+ _ATPF = GetProfileInt(_T("SubtitleSource"), _T("atpf"), 400000);
+ if(_ATPF <= 0) _ATPF = 400000;
+ WriteProfileInt(_T("SubtitleSource"), _T("w"), _WIDTH);
+ WriteProfileInt(_T("SubtitleSource"), _T("h"), _HEIGHT);
+ WriteProfileInt(_T("SubtitleSource"), _T("atpf"), _ATPF);
+
+ return TRUE;
+ }
};
CSubtitleSourceApp theApp;
@@ -147,7 +147,7 @@ CSubtitleSourceApp theApp;
//
CSubtitleSource::CSubtitleSource(LPUNKNOWN lpunk, HRESULT* phr, const CLSID& clsid)
- : CSource(NAME("CSubtitleSource"), lpunk, clsid)
+ : CSource(NAME("CSubtitleSource"), lpunk, clsid)
{
}
@@ -159,134 +159,134 @@ STDMETHODIMP CSubtitleSource::NonDelegatingQueryInterface(REFIID riid, void** pp
{
CheckPointer(ppv, E_POINTER);
- return
- QI(IFileSourceFilter)
- QI(IAMFilterMiscFlags)
- __super::NonDelegatingQueryInterface(riid, ppv);
+ return
+ QI(IFileSourceFilter)
+ QI(IAMFilterMiscFlags)
+ __super::NonDelegatingQueryInterface(riid, ppv);
}
// IFileSourceFilter
-STDMETHODIMP CSubtitleSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
+STDMETHODIMP CSubtitleSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
{
- if(GetPinCount() > 0)
- return VFW_E_ALREADY_CONNECTED;
+ if(GetPinCount() > 0)
+ return VFW_E_ALREADY_CONNECTED;
- HRESULT hr = S_OK;
- if(!(DNew CSubtitleStream(pszFileName, this, &hr)))
- return E_OUTOFMEMORY;
+ HRESULT hr = S_OK;
+ if(!(DNew CSubtitleStream(pszFileName, this, &hr)))
+ return E_OUTOFMEMORY;
- if(FAILED(hr))
- return hr;
+ if(FAILED(hr))
+ return hr;
- m_fn = pszFileName;
+ m_fn = pszFileName;
- return S_OK;
+ return S_OK;
}
STDMETHODIMP CSubtitleSource::GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
{
- if(!ppszFileName) return E_POINTER;
-
- if(!(*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength()+1)*sizeof(WCHAR))))
- return E_OUTOFMEMORY;
+ if(!ppszFileName) return E_POINTER;
- wcscpy(*ppszFileName, m_fn);
+ if(!(*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength() + 1) * sizeof(WCHAR))))
+ return E_OUTOFMEMORY;
- return S_OK;
+ wcscpy(*ppszFileName, m_fn);
+
+ return S_OK;
}
// IAMFilterMiscFlags
ULONG CSubtitleSource::GetMiscFlags()
{
- return AM_FILTER_MISC_FLAGS_IS_SOURCE;
+ return AM_FILTER_MISC_FLAGS_IS_SOURCE;
}
//
// CSubtitleStream
//
-CSubtitleStream::CSubtitleStream(const WCHAR* wfn, CSubtitleSource* pParent, HRESULT* phr)
- : CSourceStream(NAME("SubtitleStream"), phr, pParent, L"Output")
- , CSourceSeeking(NAME("SubtitleStream"), (IPin*)this, phr, &m_cSharedState)
- , m_bDiscontinuity(FALSE), m_bFlushing(FALSE)
- , m_nPosition(0)
- , m_rts(NULL)
+CSubtitleStream::CSubtitleStream(const WCHAR* wfn, CSubtitleSource* pParent, HRESULT* phr)
+ : CSourceStream(NAME("SubtitleStream"), phr, pParent, L"Output")
+ , CSourceSeeking(NAME("SubtitleStream"), (IPin*)this, phr, &m_cSharedState)
+ , m_bDiscontinuity(FALSE), m_bFlushing(FALSE)
+ , m_nPosition(0)
+ , m_rts(NULL)
{
- CAutoLock cAutoLock(&m_cSharedState);
+ CAutoLock cAutoLock(&m_cSharedState);
- CString fn(wfn);
+ CString fn(wfn);
- if(!m_rts.Open(fn, DEFAULT_CHARSET))
- {
- if(phr) *phr = E_FAIL;
- return;
- }
+ if(!m_rts.Open(fn, DEFAULT_CHARSET))
+ {
+ if(phr) *phr = E_FAIL;
+ return;
+ }
- m_rts.CreateDefaultStyle(DEFAULT_CHARSET);
- m_rts.ConvertToTimeBased(25);
- m_rts.Sort();
+ m_rts.CreateDefaultStyle(DEFAULT_CHARSET);
+ m_rts.ConvertToTimeBased(25);
+ m_rts.Sort();
- m_rtDuration = 0;
- for(int i = 0, cnt = m_rts.GetCount(); i < cnt; i++)
- m_rtDuration = max(m_rtDuration, 10000i64*m_rts[i].end);
+ m_rtDuration = 0;
+ for(int i = 0, cnt = m_rts.GetCount(); i < cnt; i++)
+ m_rtDuration = max(m_rtDuration, 10000i64 * m_rts[i].end);
- m_rtStop = m_rtDuration;
+ m_rtStop = m_rtDuration;
- if(phr) *phr = m_rtDuration > 0 ? S_OK : E_FAIL;
+ if(phr) *phr = m_rtDuration > 0 ? S_OK : E_FAIL;
}
CSubtitleStream::~CSubtitleStream()
{
- CAutoLock cAutoLock(&m_cSharedState);
+ CAutoLock cAutoLock(&m_cSharedState);
}
STDMETHODIMP CSubtitleStream::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
CheckPointer(ppv, E_POINTER);
- return (riid == IID_IMediaSeeking) ? CSourceSeeking::NonDelegatingQueryInterface(riid, ppv) //GetInterface((IMediaSeeking*)this, ppv)
- : CSourceStream::NonDelegatingQueryInterface(riid, ppv);
+ return (riid == IID_IMediaSeeking) ? CSourceSeeking::NonDelegatingQueryInterface(riid, ppv) //GetInterface((IMediaSeeking*)this, ppv)
+ : CSourceStream::NonDelegatingQueryInterface(riid, ppv);
}
void CSubtitleStream::UpdateFromSeek()
{
- if(ThreadExists())
- {
- // next time around the loop, the worker thread will
- // pick up the position change.
- // We need to flush all the existing data - we must do that here
- // as our thread will probably be blocked in GetBuffer otherwise
-
- m_bFlushing = TRUE;
-
- DeliverBeginFlush();
- // make sure we have stopped pushing
- Stop();
- // complete the flush
- DeliverEndFlush();
+ if(ThreadExists())
+ {
+ // next time around the loop, the worker thread will
+ // pick up the position change.
+ // We need to flush all the existing data - we must do that here
+ // as our thread will probably be blocked in GetBuffer otherwise
+
+ m_bFlushing = TRUE;
+
+ DeliverBeginFlush();
+ // make sure we have stopped pushing
+ Stop();
+ // complete the flush
+ DeliverEndFlush();
m_bFlushing = FALSE;
- // restart
- Run();
- }
+ // restart
+ Run();
+ }
}
HRESULT CSubtitleStream::SetRate(double dRate)
{
- if(dRate <= 0)
- return E_INVALIDARG;
+ if(dRate <= 0)
+ return E_INVALIDARG;
- {
- CAutoLock lock(CSourceSeeking::m_pLock);
- m_dRateSeeking = dRate;
- }
+ {
+ CAutoLock lock(CSourceSeeking::m_pLock);
+ m_dRateSeeking = dRate;
+ }
- UpdateFromSeek();
+ UpdateFromSeek();
- return S_OK;
+ return S_OK;
}
HRESULT CSubtitleStream::OnThreadStartPlay()
@@ -300,25 +300,26 @@ HRESULT CSubtitleStream::ChangeStart()
{
CAutoLock lock(CSourceSeeking::m_pLock);
- OnThreadCreate();
-/*
- if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_ARGB32)
- {
- m_nPosition = (int)(m_rtStart/10000)*1/1000;
- }
- else if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_RGB32)
- {
- int m_nSegments = 0;
- if(!m_rts.SearchSubs((int)(m_rtStart/10000), 25, &m_nPosition, &m_nSegments))
- m_nPosition = m_nSegments;
- }
- else
- {
- m_nPosition = m_rts.SearchSub((int)(m_rtStart/10000), 25);
- if(m_nPosition < 0) m_nPosition = 0;
- else if(m_rts[m_nPosition].end <= (int)(m_rtStart/10000)) m_nPosition++;
- }
-*/ }
+ OnThreadCreate();
+ /*
+ if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_ARGB32)
+ {
+ m_nPosition = (int)(m_rtStart/10000)*1/1000;
+ }
+ else if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_RGB32)
+ {
+ int m_nSegments = 0;
+ if(!m_rts.SearchSubs((int)(m_rtStart/10000), 25, &m_nPosition, &m_nSegments))
+ m_nPosition = m_nSegments;
+ }
+ else
+ {
+ m_nPosition = m_rts.SearchSub((int)(m_rtStart/10000), 25);
+ if(m_nPosition < 0) m_nPosition = 0;
+ else if(m_rts[m_nPosition].end <= (int)(m_rtStart/10000)) m_nPosition++;
+ }
+ */
+ }
UpdateFromSeek();
@@ -327,13 +328,13 @@ HRESULT CSubtitleStream::ChangeStart()
HRESULT CSubtitleStream::ChangeStop()
{
-/*
- {
- CAutoLock lock(CSourceSeeking::m_pLock);
- if(m_rtPosition < m_rtStop)
- return S_OK;
- }
-*/
+ /*
+ {
+ CAutoLock lock(CSourceSeeking::m_pLock);
+ if(m_rtPosition < m_rtStop)
+ return S_OK;
+ }
+ */
// We're already past the new stop time -- better flush the graph.
UpdateFromSeek();
@@ -344,22 +345,22 @@ HRESULT CSubtitleStream::OnThreadCreate()
{
CAutoLock cAutoLockShared(&m_cSharedState);
- if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_ARGB32)
- {
- m_nPosition = m_rtStart/_ATPF;
- }
- else if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_RGB32)
- {
- int m_nSegments = 0;
- if(!m_rts.SearchSubs((int)(m_rtStart/10000), 10000000/_ATPF, &m_nPosition, &m_nSegments))
- m_nPosition = m_nSegments;
- }
- else
- {
- m_nPosition = m_rts.SearchSub((int)(m_rtStart/10000), 25);
- if(m_nPosition < 0) m_nPosition = 0;
- else if(m_rts[m_nPosition].end <= (int)(m_rtStart/10000)) m_nPosition++;
- }
+ if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_ARGB32)
+ {
+ m_nPosition = m_rtStart / _ATPF;
+ }
+ else if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_RGB32)
+ {
+ int m_nSegments = 0;
+ if(!m_rts.SearchSubs((int)(m_rtStart / 10000), 10000000 / _ATPF, &m_nPosition, &m_nSegments))
+ m_nPosition = m_nSegments;
+ }
+ else
+ {
+ m_nPosition = m_rts.SearchSub((int)(m_rtStart / 10000), 25);
+ if(m_nPosition < 0) m_nPosition = 0;
+ else if(m_rts[m_nPosition].end <= (int)(m_rtStart / 10000)) m_nPosition++;
+ }
return CSourceStream::OnThreadCreate();
}
@@ -373,16 +374,16 @@ HRESULT CSubtitleStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPE
HRESULT hr = NOERROR;
- if(m_mt.majortype == MEDIATYPE_Video)
- {
- pProperties->cBuffers = 2;
- pProperties->cbBuffer = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biSizeImage;
- }
- else
- {
- pProperties->cBuffers = 1;
- pProperties->cbBuffer = 0x10000;
- }
+ if(m_mt.majortype == MEDIATYPE_Video)
+ {
+ pProperties->cBuffers = 2;
+ pProperties->cbBuffer = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biSizeImage;
+ }
+ else
+ {
+ pProperties->cBuffers = 1;
+ pProperties->cbBuffer = 0x10000;
+ }
ALLOCATOR_PROPERTIES Actual;
if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
@@ -395,148 +396,148 @@ HRESULT CSubtitleStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPE
HRESULT CSubtitleStream::FillBuffer(IMediaSample* pSample)
{
- HRESULT hr;
-
- {
- CAutoLock cAutoLockShared(&m_cSharedState);
-
- BYTE* pData = NULL;
- if(FAILED(hr = pSample->GetPointer(&pData)) || !pData)
- return S_FALSE;
-
- AM_MEDIA_TYPE* pmt;
- if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt)
- {
- CMediaType mt(*pmt);
- SetMediaType(&mt);
- DeleteMediaType(pmt);
- }
-
- int len = 0;
- REFERENCE_TIME rtStart, rtStop;
-
- if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_ARGB32)
- {
- rtStart = (REFERENCE_TIME)((m_nPosition*_ATPF - m_rtStart) / m_dRateSeeking);
- rtStop = (REFERENCE_TIME)(((m_nPosition+1)*_ATPF - m_rtStart) / m_dRateSeeking);
- if(m_rtStart+rtStart >= m_rtDuration)
- return S_FALSE;
-
- BITMAPINFOHEADER& bmi = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader;
-
- SubPicDesc spd;
- spd.w = _WIDTH;
- spd.h = _HEIGHT;
- spd.bpp = 32;
- spd.pitch = bmi.biWidth*4;
- spd.bits = pData;
-
- len = spd.h*spd.pitch;
-
- for(int y = 0; y < spd.h; y++)
- memsetd((DWORD*)(pData + spd.pitch*y), 0xff000000, spd.w*4);
-
- RECT bbox;
- m_rts.Render(spd, m_nPosition*_ATPF, 10000000.0/_ATPF, bbox);
-
- for(int y = 0; y < spd.h; y++)
- {
- DWORD* p = (DWORD*)(pData + spd.pitch*y);
- for(int x = 0; x < spd.w; x++, p++)
- *p = (0xff000000-(*p&0xff000000))|(*p&0xffffff);
- }
- }
- else if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_RGB32)
- {
- const STSSegment* stss = m_rts.GetSegment(m_nPosition);
- if(!stss) return S_FALSE;
-
- BITMAPINFOHEADER& bmi = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader;
-
- SubPicDesc spd;
- spd.w = _WIDTH;
- spd.h = _HEIGHT;
- spd.bpp = 32;
- spd.pitch = bmi.biWidth*4;
- spd.bits = pData;
-
- len = spd.h*spd.pitch;
-
- for(int y = 0; y < spd.h; y++)
- {
- DWORD c1 = 0xff606060, c2 = 0xffa0a0a0;
- if(y&32) c1 ^= c2, c2 ^= c1, c1 ^= c2;
- DWORD* p = (DWORD*)(pData + spd.pitch*y);
- for(int x = 0; x < spd.w; x+=32, p+=32)
- memsetd(p, (x&32) ? c1 : c2, min(spd.w-x,32)*4);
- }
-
- RECT bbox;
- m_rts.Render(spd, 10000i64*(stss->start+stss->end)/2, 10000000.0/_ATPF, bbox);
-
- rtStart = (REFERENCE_TIME)((10000i64*stss->start - m_rtStart) / m_dRateSeeking);
- rtStop = (REFERENCE_TIME)((10000i64*stss->end - m_rtStart) / m_dRateSeeking);
- }
- else
- {
- if(m_nPosition >= m_rts.GetCount())
- return S_FALSE;
-
- STSEntry& stse = m_rts[m_nPosition];
-
- if(stse.start >= m_rtStop/10000)
- return S_FALSE;
-
- if(m_mt.majortype == MEDIATYPE_Subtitle && m_mt.subtype == MEDIASUBTYPE_UTF8)
- {
- CStringA str = UTF16To8(m_rts.GetStrW(m_nPosition, false));
- memcpy((char*)pData, str, len = str.GetLength());
- }
- else if(m_mt.majortype == MEDIATYPE_Subtitle && (m_mt.subtype == MEDIASUBTYPE_SSA || m_mt.subtype == MEDIASUBTYPE_ASS))
- {
- CStringW line;
- line.Format(L"%d,%d,%s,%s,%d,%d,%d,%s,%s",
- stse.readorder, stse.layer, CStringW(stse.style), CStringW(stse.actor),
- stse.marginRect.left, stse.marginRect.right, (stse.marginRect.top+stse.marginRect.bottom)/2,
- CStringW(stse.effect), m_rts.GetStrW(m_nPosition, true));
-
- CStringA str = UTF16To8(line);
- memcpy((char*)pData, str, len = str.GetLength());
- }
- else if(m_mt.majortype == MEDIATYPE_Text && m_mt.subtype == MEDIASUBTYPE_NULL)
- {
- CStringA str = m_rts.GetStrA(m_nPosition, false);
- memcpy((char*)pData, str, len = str.GetLength());
- }
- else
- {
- return S_FALSE;
- }
-
- rtStart = (REFERENCE_TIME)((10000i64*stse.start - m_rtStart) / m_dRateSeeking);
- rtStop = (REFERENCE_TIME)((10000i64*stse.end - m_rtStart) / m_dRateSeeking);
- }
-
- pSample->SetTime(&rtStart, &rtStop);
- pSample->SetActualDataLength(len);
-
- m_nPosition++;
- }
-
- pSample->SetSyncPoint(TRUE);
-
- if(m_bDiscontinuity)
+ HRESULT hr;
+
{
- pSample->SetDiscontinuity(TRUE);
- m_bDiscontinuity = FALSE;
- }
+ CAutoLock cAutoLockShared(&m_cSharedState);
+
+ BYTE* pData = NULL;
+ if(FAILED(hr = pSample->GetPointer(&pData)) || !pData)
+ return S_FALSE;
+
+ AM_MEDIA_TYPE* pmt;
+ if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt)
+ {
+ CMediaType mt(*pmt);
+ SetMediaType(&mt);
+ DeleteMediaType(pmt);
+ }
+
+ int len = 0;
+ REFERENCE_TIME rtStart, rtStop;
+
+ if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_ARGB32)
+ {
+ rtStart = (REFERENCE_TIME)((m_nPosition * _ATPF - m_rtStart) / m_dRateSeeking);
+ rtStop = (REFERENCE_TIME)(((m_nPosition + 1) * _ATPF - m_rtStart) / m_dRateSeeking);
+ if(m_rtStart + rtStart >= m_rtDuration)
+ return S_FALSE;
+
+ BITMAPINFOHEADER& bmi = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader;
+
+ SubPicDesc spd;
+ spd.w = _WIDTH;
+ spd.h = _HEIGHT;
+ spd.bpp = 32;
+ spd.pitch = bmi.biWidth * 4;
+ spd.bits = pData;
+
+ len = spd.h * spd.pitch;
+
+ for(int y = 0; y < spd.h; y++)
+ memsetd((DWORD*)(pData + spd.pitch * y), 0xff000000, spd.w * 4);
+
+ RECT bbox;
+ m_rts.Render(spd, m_nPosition * _ATPF, 10000000.0 / _ATPF, bbox);
+
+ for(int y = 0; y < spd.h; y++)
+ {
+ DWORD* p = (DWORD*)(pData + spd.pitch * y);
+ for(int x = 0; x < spd.w; x++, p++)
+ *p = (0xff000000 - (*p & 0xff000000)) | (*p & 0xffffff);
+ }
+ }
+ else if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_RGB32)
+ {
+ const STSSegment* stss = m_rts.GetSegment(m_nPosition);
+ if(!stss) return S_FALSE;
+
+ BITMAPINFOHEADER& bmi = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader;
+
+ SubPicDesc spd;
+ spd.w = _WIDTH;
+ spd.h = _HEIGHT;
+ spd.bpp = 32;
+ spd.pitch = bmi.biWidth * 4;
+ spd.bits = pData;
+
+ len = spd.h * spd.pitch;
+
+ for(int y = 0; y < spd.h; y++)
+ {
+ DWORD c1 = 0xff606060, c2 = 0xffa0a0a0;
+ if(y & 32) c1 ^= c2, c2 ^= c1, c1 ^= c2;
+ DWORD* p = (DWORD*)(pData + spd.pitch * y);
+ for(int x = 0; x < spd.w; x += 32, p += 32)
+ memsetd(p, (x & 32) ? c1 : c2, min(spd.w - x, 32) * 4);
+ }
+
+ RECT bbox;
+ m_rts.Render(spd, 10000i64 *(stss->start + stss->end) / 2, 10000000.0 / _ATPF, bbox);
+
+ rtStart = (REFERENCE_TIME)((10000i64 * stss->start - m_rtStart) / m_dRateSeeking);
+ rtStop = (REFERENCE_TIME)((10000i64 * stss->end - m_rtStart) / m_dRateSeeking);
+ }
+ else
+ {
+ if(m_nPosition >= m_rts.GetCount())
+ return S_FALSE;
+
+ STSEntry& stse = m_rts[m_nPosition];
+
+ if(stse.start >= m_rtStop / 10000)
+ return S_FALSE;
+
+ if(m_mt.majortype == MEDIATYPE_Subtitle && m_mt.subtype == MEDIASUBTYPE_UTF8)
+ {
+ CStringA str = UTF16To8(m_rts.GetStrW(m_nPosition, false));
+ memcpy((char*)pData, str, len = str.GetLength());
+ }
+ else if(m_mt.majortype == MEDIATYPE_Subtitle && (m_mt.subtype == MEDIASUBTYPE_SSA || m_mt.subtype == MEDIASUBTYPE_ASS))
+ {
+ CStringW line;
+ line.Format(L"%d,%d,%s,%s,%d,%d,%d,%s,%s",
+ stse.readorder, stse.layer, CStringW(stse.style), CStringW(stse.actor),
+ stse.marginRect.left, stse.marginRect.right, (stse.marginRect.top + stse.marginRect.bottom) / 2,
+ CStringW(stse.effect), m_rts.GetStrW(m_nPosition, true));
+
+ CStringA str = UTF16To8(line);
+ memcpy((char*)pData, str, len = str.GetLength());
+ }
+ else if(m_mt.majortype == MEDIATYPE_Text && m_mt.subtype == MEDIASUBTYPE_NULL)
+ {
+ CStringA str = m_rts.GetStrA(m_nPosition, false);
+ memcpy((char*)pData, str, len = str.GetLength());
+ }
+ else
+ {
+ return S_FALSE;
+ }
+
+ rtStart = (REFERENCE_TIME)((10000i64 * stse.start - m_rtStart) / m_dRateSeeking);
+ rtStop = (REFERENCE_TIME)((10000i64 * stse.end - m_rtStart) / m_dRateSeeking);
+ }
+
+ pSample->SetTime(&rtStart, &rtStop);
+ pSample->SetActualDataLength(len);
+
+ m_nPosition++;
+ }
+
+ pSample->SetSyncPoint(TRUE);
- return S_OK;
+ if(m_bDiscontinuity)
+ {
+ pSample->SetDiscontinuity(TRUE);
+ m_bDiscontinuity = FALSE;
+ }
+
+ return S_OK;
}
HRESULT CSubtitleStream::GetMediaType(CMediaType* pmt)
{
- return (static_cast<CSubtitleSource*>(m_pFilter))->GetMediaType(pmt);
+ return (static_cast<CSubtitleSource*>(m_pFilter))->GetMediaType(pmt);
}
HRESULT CSubtitleStream::CheckMediaType(const CMediaType* pmt)
@@ -546,8 +547,8 @@ HRESULT CSubtitleStream::CheckMediaType(const CMediaType* pmt)
CMediaType mt;
GetMediaType(&mt);
- if(mt.majortype == pmt->majortype && mt.subtype == pmt->subtype)
- {
+ if(mt.majortype == pmt->majortype && mt.subtype == pmt->subtype)
+ {
return NOERROR;
}
@@ -556,7 +557,7 @@ HRESULT CSubtitleStream::CheckMediaType(const CMediaType* pmt)
STDMETHODIMP CSubtitleStream::Notify(IBaseFilter* pSender, Quality q)
{
- return E_NOTIMPL;
+ return E_NOTIMPL;
}
//
@@ -564,7 +565,7 @@ STDMETHODIMP CSubtitleStream::Notify(IBaseFilter* pSender, Quality q)
//
CSubtitleSourceASCII::CSubtitleSourceASCII(LPUNKNOWN lpunk, HRESULT* phr)
- : CSubtitleSource(lpunk, phr, __uuidof(this))
+ : CSubtitleSource(lpunk, phr, __uuidof(this))
{
}
@@ -572,11 +573,11 @@ HRESULT CSubtitleSourceASCII::GetMediaType(CMediaType* pmt)
{
CAutoLock cAutoLock(pStateLock());
- pmt->InitMediaType();
- pmt->SetType(&MEDIATYPE_Text);
- pmt->SetSubtype(&MEDIASUBTYPE_NULL);
- pmt->SetFormatType(&FORMAT_None);
- pmt->ResetFormatBuffer();
+ pmt->InitMediaType();
+ pmt->SetType(&MEDIATYPE_Text);
+ pmt->SetSubtype(&MEDIASUBTYPE_NULL);
+ pmt->SetFormatType(&FORMAT_None);
+ pmt->ResetFormatBuffer();
return NOERROR;
}
@@ -586,7 +587,7 @@ HRESULT CSubtitleSourceASCII::GetMediaType(CMediaType* pmt)
//
CSubtitleSourceUTF8::CSubtitleSourceUTF8(LPUNKNOWN lpunk, HRESULT* phr)
- : CSubtitleSource(lpunk, phr, __uuidof(this))
+ : CSubtitleSource(lpunk, phr, __uuidof(this))
{
}
@@ -594,13 +595,13 @@ HRESULT CSubtitleSourceUTF8::GetMediaType(CMediaType* pmt)
{
CAutoLock cAutoLock(pStateLock());
- pmt->InitMediaType();
- pmt->SetType(&MEDIATYPE_Subtitle);
- pmt->SetSubtype(&MEDIASUBTYPE_UTF8);
- pmt->SetFormatType(&FORMAT_SubtitleInfo);
- SUBTITLEINFO* psi = (SUBTITLEINFO*)pmt->AllocFormatBuffer(sizeof(SUBTITLEINFO));
- memset(psi, 0, pmt->FormatLength());
- strcpy(psi->IsoLang, "eng");
+ pmt->InitMediaType();
+ pmt->SetType(&MEDIATYPE_Subtitle);
+ pmt->SetSubtype(&MEDIASUBTYPE_UTF8);
+ pmt->SetFormatType(&FORMAT_SubtitleInfo);
+ SUBTITLEINFO* psi = (SUBTITLEINFO*)pmt->AllocFormatBuffer(sizeof(SUBTITLEINFO));
+ memset(psi, 0, pmt->FormatLength());
+ strcpy(psi->IsoLang, "eng");
return NOERROR;
}
@@ -610,7 +611,7 @@ HRESULT CSubtitleSourceUTF8::GetMediaType(CMediaType* pmt)
//
CSubtitleSourceSSA::CSubtitleSourceSSA(LPUNKNOWN lpunk, HRESULT* phr)
- : CSubtitleSource(lpunk, phr, __uuidof(this))
+ : CSubtitleSource(lpunk, phr, __uuidof(this))
{
}
@@ -618,38 +619,38 @@ HRESULT CSubtitleSourceSSA::GetMediaType(CMediaType* pmt)
{
CAutoLock cAutoLock(pStateLock());
- pmt->InitMediaType();
- pmt->SetType(&MEDIATYPE_Subtitle);
- pmt->SetSubtype(&MEDIASUBTYPE_SSA);
- pmt->SetFormatType(&FORMAT_SubtitleInfo);
+ pmt->InitMediaType();
+ pmt->SetType(&MEDIATYPE_Subtitle);
+ pmt->SetSubtype(&MEDIASUBTYPE_SSA);
+ pmt->SetFormatType(&FORMAT_SubtitleInfo);
- CSimpleTextSubtitle sts;
- sts.Open(CString(m_fn), DEFAULT_CHARSET);
- sts.RemoveAll();
+ CSimpleTextSubtitle sts;
+ sts.Open(CString(m_fn), DEFAULT_CHARSET);
+ sts.RemoveAll();
- CFile f;
- TCHAR path[_MAX_PATH], fn[_MAX_PATH];
- if(!GetTempPath(MAX_PATH, path) || !GetTempFileName(path, _T("mpc_sts"), 0, fn))
- return E_FAIL;
+ CFile f;
+ TCHAR path[_MAX_PATH], fn[_MAX_PATH];
+ if(!GetTempPath(MAX_PATH, path) || !GetTempFileName(path, _T("mpc_sts"), 0, fn))
+ return E_FAIL;
- _tremove(fn);
+ _tremove(fn);
- _tcscat(fn, _T(".ssa"));
+ _tcscat(fn, _T(".ssa"));
- if(!sts.SaveAs(fn, EXTSSA, -1, CTextFile::UTF8) || !f.Open(fn, CFile::modeRead))
- return E_FAIL;
+ if(!sts.SaveAs(fn, EXTSSA, -1, CTextFile::UTF8) || !f.Open(fn, CFile::modeRead))
+ return E_FAIL;
- int len = (int)f.GetLength()-3;
- f.Seek(3, CFile::begin);
+ int len = (int)f.GetLength() - 3;
+ f.Seek(3, CFile::begin);
- SUBTITLEINFO* psi = (SUBTITLEINFO*)pmt->AllocFormatBuffer(sizeof(SUBTITLEINFO) + len);
- memset(psi, 0, pmt->FormatLength());
- psi->dwOffset = sizeof(SUBTITLEINFO);
- strcpy(psi->IsoLang, "eng");
- f.Read(pmt->pbFormat + psi->dwOffset, len);
- f.Close();
+ SUBTITLEINFO* psi = (SUBTITLEINFO*)pmt->AllocFormatBuffer(sizeof(SUBTITLEINFO) + len);
+ memset(psi, 0, pmt->FormatLength());
+ psi->dwOffset = sizeof(SUBTITLEINFO);
+ strcpy(psi->IsoLang, "eng");
+ f.Read(pmt->pbFormat + psi->dwOffset, len);
+ f.Close();
- _tremove(fn);
+ _tremove(fn);
return NOERROR;
}
@@ -659,7 +660,7 @@ HRESULT CSubtitleSourceSSA::GetMediaType(CMediaType* pmt)
//
CSubtitleSourceASS::CSubtitleSourceASS(LPUNKNOWN lpunk, HRESULT* phr)
- : CSubtitleSource(lpunk, phr, __uuidof(this))
+ : CSubtitleSource(lpunk, phr, __uuidof(this))
{
}
@@ -667,37 +668,37 @@ HRESULT CSubtitleSourceASS::GetMediaType(CMediaType* pmt)
{
CAutoLock cAutoLock(pStateLock());
- pmt->InitMediaType();
- pmt->SetType(&MEDIATYPE_Subtitle);
- pmt->SetSubtype(&MEDIASUBTYPE_ASS);
- pmt->SetFormatType(&FORMAT_SubtitleInfo);
+ pmt->InitMediaType();
+ pmt->SetType(&MEDIATYPE_Subtitle);
+ pmt->SetSubtype(&MEDIASUBTYPE_ASS);
+ pmt->SetFormatType(&FORMAT_SubtitleInfo);
- CSimpleTextSubtitle sts;
- sts.Open(CString(m_fn), DEFAULT_CHARSET);
- sts.RemoveAll();
+ CSimpleTextSubtitle sts;
+ sts.Open(CString(m_fn), DEFAULT_CHARSET);
+ sts.RemoveAll();
- CFile f;
- TCHAR path[_MAX_PATH], fn[_MAX_PATH];
- if(!GetTempPath(MAX_PATH, path) || !GetTempFileName(path, _T("mpc_sts"), 0, fn))
- return E_FAIL;
+ CFile f;
+ TCHAR path[_MAX_PATH], fn[_MAX_PATH];
+ if(!GetTempPath(MAX_PATH, path) || !GetTempFileName(path, _T("mpc_sts"), 0, fn))
+ return E_FAIL;
- _tremove(fn);
+ _tremove(fn);
- _tcscat(fn, _T(".ass"));
+ _tcscat(fn, _T(".ass"));
- if(!sts.SaveAs(fn, EXTASS, -1, CTextFile::UTF8) || !f.Open(fn, CFile::modeRead))
- return E_FAIL;
+ if(!sts.SaveAs(fn, EXTASS, -1, CTextFile::UTF8) || !f.Open(fn, CFile::modeRead))
+ return E_FAIL;
- int len = (int)f.GetLength();
+ int len = (int)f.GetLength();
- SUBTITLEINFO* psi = (SUBTITLEINFO*)pmt->AllocFormatBuffer(sizeof(SUBTITLEINFO) + len);
- memset(psi, 0, pmt->FormatLength());
- psi->dwOffset = sizeof(SUBTITLEINFO);
- strcpy(psi->IsoLang, "eng");
- f.Read(pmt->pbFormat + psi->dwOffset, len);
- f.Close();
+ SUBTITLEINFO* psi = (SUBTITLEINFO*)pmt->AllocFormatBuffer(sizeof(SUBTITLEINFO) + len);
+ memset(psi, 0, pmt->FormatLength());
+ psi->dwOffset = sizeof(SUBTITLEINFO);
+ strcpy(psi->IsoLang, "eng");
+ f.Read(pmt->pbFormat + psi->dwOffset, len);
+ f.Close();
- _tremove(fn);
+ _tremove(fn);
return NOERROR;
}
@@ -707,7 +708,7 @@ HRESULT CSubtitleSourceASS::GetMediaType(CMediaType* pmt)
//
CSubtitleSourceUSF::CSubtitleSourceUSF(LPUNKNOWN lpunk, HRESULT* phr)
- : CSubtitleSource(lpunk, phr, __uuidof(this))
+ : CSubtitleSource(lpunk, phr, __uuidof(this))
{
}
@@ -715,14 +716,14 @@ HRESULT CSubtitleSourceUSF::GetMediaType(CMediaType* pmt)
{
CAutoLock cAutoLock(pStateLock());
- pmt->InitMediaType();
- pmt->SetType(&MEDIATYPE_Subtitle);
- pmt->SetSubtype(&MEDIASUBTYPE_USF);
- pmt->SetFormatType(&FORMAT_SubtitleInfo);
- SUBTITLEINFO* psi = (SUBTITLEINFO*)pmt->AllocFormatBuffer(sizeof(SUBTITLEINFO));
- memset(psi, 0, pmt->FormatLength());
- strcpy(psi->IsoLang, "eng");
- // TODO: ...
+ pmt->InitMediaType();
+ pmt->SetType(&MEDIATYPE_Subtitle);
+ pmt->SetSubtype(&MEDIASUBTYPE_USF);
+ pmt->SetFormatType(&FORMAT_SubtitleInfo);
+ SUBTITLEINFO* psi = (SUBTITLEINFO*)pmt->AllocFormatBuffer(sizeof(SUBTITLEINFO));
+ memset(psi, 0, pmt->FormatLength());
+ strcpy(psi->IsoLang, "eng");
+ // TODO: ...
return NOERROR;
}
@@ -732,7 +733,7 @@ HRESULT CSubtitleSourceUSF::GetMediaType(CMediaType* pmt)
//
CSubtitleSourcePreview::CSubtitleSourcePreview(LPUNKNOWN lpunk, HRESULT* phr)
- : CSubtitleSource(lpunk, phr, __uuidof(this))
+ : CSubtitleSource(lpunk, phr, __uuidof(this))
{
}
@@ -740,19 +741,19 @@ HRESULT CSubtitleSourcePreview::GetMediaType(CMediaType* pmt)
{
CAutoLock cAutoLock(pStateLock());
- pmt->InitMediaType();
- pmt->SetType(&MEDIATYPE_Video);
- pmt->SetSubtype(&MEDIASUBTYPE_RGB32);
- pmt->SetFormatType(&FORMAT_VideoInfo);
- VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
- memset(pvih, 0, pmt->FormatLength());
- pvih->bmiHeader.biSize = sizeof(pvih->bmiHeader);
- pvih->bmiHeader.biWidth = _WIDTH;
- pvih->bmiHeader.biHeight = _HEIGHT;
- pvih->bmiHeader.biBitCount = 32;
- pvih->bmiHeader.biCompression = BI_RGB;
- pvih->bmiHeader.biPlanes = 1;
- pvih->bmiHeader.biSizeImage = pvih->bmiHeader.biWidth*abs(pvih->bmiHeader.biHeight)*pvih->bmiHeader.biBitCount>>3;
+ pmt->InitMediaType();
+ pmt->SetType(&MEDIATYPE_Video);
+ pmt->SetSubtype(&MEDIASUBTYPE_RGB32);
+ pmt->SetFormatType(&FORMAT_VideoInfo);
+ VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
+ memset(pvih, 0, pmt->FormatLength());
+ pvih->bmiHeader.biSize = sizeof(pvih->bmiHeader);
+ pvih->bmiHeader.biWidth = _WIDTH;
+ pvih->bmiHeader.biHeight = _HEIGHT;
+ pvih->bmiHeader.biBitCount = 32;
+ pvih->bmiHeader.biCompression = BI_RGB;
+ pvih->bmiHeader.biPlanes = 1;
+ pvih->bmiHeader.biSizeImage = pvih->bmiHeader.biWidth * abs(pvih->bmiHeader.biHeight) * pvih->bmiHeader.biBitCount >> 3;
return NOERROR;
}
@@ -762,7 +763,7 @@ HRESULT CSubtitleSourcePreview::GetMediaType(CMediaType* pmt)
//
CSubtitleSourceARGB::CSubtitleSourceARGB(LPUNKNOWN lpunk, HRESULT* phr)
- : CSubtitleSource(lpunk, phr, __uuidof(this))
+ : CSubtitleSource(lpunk, phr, __uuidof(this))
{
}
@@ -770,20 +771,20 @@ HRESULT CSubtitleSourceARGB::GetMediaType(CMediaType* pmt)
{
CAutoLock cAutoLock(pStateLock());
- pmt->InitMediaType();
- pmt->SetType(&MEDIATYPE_Video);
- pmt->SetSubtype(&MEDIASUBTYPE_ARGB32);
- pmt->SetFormatType(&FORMAT_VideoInfo);
- VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
- memset(pvih, 0, pmt->FormatLength());
- pvih->bmiHeader.biSize = sizeof(pvih->bmiHeader);
- // TODO: read w,h,fps from a config file or registry
- pvih->bmiHeader.biWidth = _WIDTH;
- pvih->bmiHeader.biHeight = _HEIGHT;
- pvih->bmiHeader.biBitCount = 32;
- pvih->bmiHeader.biCompression = BI_RGB;
- pvih->bmiHeader.biPlanes = 1;
- pvih->bmiHeader.biSizeImage = pvih->bmiHeader.biWidth*abs(pvih->bmiHeader.biHeight)*pvih->bmiHeader.biBitCount>>3;
+ pmt->InitMediaType();
+ pmt->SetType(&MEDIATYPE_Video);
+ pmt->SetSubtype(&MEDIASUBTYPE_ARGB32);
+ pmt->SetFormatType(&FORMAT_VideoInfo);
+ VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
+ memset(pvih, 0, pmt->FormatLength());
+ pvih->bmiHeader.biSize = sizeof(pvih->bmiHeader);
+ // TODO: read w,h,fps from a config file or registry
+ pvih->bmiHeader.biWidth = _WIDTH;
+ pvih->bmiHeader.biHeight = _HEIGHT;
+ pvih->bmiHeader.biBitCount = 32;
+ pvih->bmiHeader.biCompression = BI_RGB;
+ pvih->bmiHeader.biPlanes = 1;
+ pvih->bmiHeader.biSizeImage = pvih->bmiHeader.biWidth * abs(pvih->bmiHeader.biHeight) * pvih->bmiHeader.biBitCount >> 3;
return NOERROR;
}
diff --git a/src/filters/source/SubtitleSource/SubtitleSource.h b/src/filters/source/SubtitleSource/SubtitleSource.h
index 77ef35581..8fc2acb91 100644
--- a/src/filters/source/SubtitleSource/SubtitleSource.h
+++ b/src/filters/source/SubtitleSource/SubtitleSource.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
@@ -25,127 +25,130 @@
#include "../../../subtitles/RTS.h"
class CSubtitleSource
- : public CSource
- , public IFileSourceFilter
- , public IAMFilterMiscFlags
+ : public CSource
+ , public IFileSourceFilter
+ , public IAMFilterMiscFlags
{
protected:
- CStringW m_fn;
+ CStringW m_fn;
public:
- CSubtitleSource(LPUNKNOWN lpunk, HRESULT* phr, const CLSID& clsid);
- virtual ~CSubtitleSource();
+ CSubtitleSource(LPUNKNOWN lpunk, HRESULT* phr, const CLSID& clsid);
+ virtual ~CSubtitleSource();
- DECLARE_IUNKNOWN;
+ DECLARE_IUNKNOWN;
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
- // IFileSourceFilter
- STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt);
- STDMETHODIMP GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt);
+ // IFileSourceFilter
+ STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt);
+ STDMETHODIMP GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt);
- // IAMFilterMiscFlags
- STDMETHODIMP_(ULONG) GetMiscFlags();
+ // IAMFilterMiscFlags
+ STDMETHODIMP_(ULONG) GetMiscFlags();
virtual HRESULT GetMediaType(CMediaType* pmt) = 0;
};
-class CSubtitleStream
- : public CSourceStream
- , public CSourceSeeking
+class CSubtitleStream
+ : public CSourceStream
+ , public CSourceSeeking
{
- CCritSec m_cSharedState;
+ CCritSec m_cSharedState;
- int m_nPosition;
+ int m_nPosition;
- BOOL m_bDiscontinuity, m_bFlushing;
+ BOOL m_bDiscontinuity, m_bFlushing;
- HRESULT OnThreadStartPlay();
- HRESULT OnThreadCreate();
+ HRESULT OnThreadStartPlay();
+ HRESULT OnThreadCreate();
- void UpdateFromSeek();
- STDMETHODIMP SetRate(double dRate);
+ void UpdateFromSeek();
+ STDMETHODIMP SetRate(double dRate);
- HRESULT ChangeStart();
+ HRESULT ChangeStart();
HRESULT ChangeStop();
- HRESULT ChangeRate() {return S_OK;}
+ HRESULT ChangeRate()
+ {
+ return S_OK;
+ }
protected:
- CRenderedTextSubtitle m_rts;
+ CRenderedTextSubtitle m_rts;
public:
CSubtitleStream(const WCHAR* wfn, CSubtitleSource* pParent, HRESULT* phr);
- virtual ~CSubtitleStream();
+ virtual ~CSubtitleStream();
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
HRESULT FillBuffer(IMediaSample* pSample);
HRESULT GetMediaType(CMediaType* pmt);
- HRESULT CheckMediaType(const CMediaType* pmt);
+ HRESULT CheckMediaType(const CMediaType* pmt);
- STDMETHODIMP Notify(IBaseFilter* pSender, Quality q);
+ STDMETHODIMP Notify(IBaseFilter* pSender, Quality q);
};
[uuid("E44CA3B5-A0FF-41A0-AF16-42429B1095EA")]
class CSubtitleSourceASCII : public CSubtitleSource
{
public:
- CSubtitleSourceASCII(LPUNKNOWN lpunk, HRESULT* phr);
+ CSubtitleSourceASCII(LPUNKNOWN lpunk, HRESULT* phr);
- HRESULT GetMediaType(CMediaType* pmt);
+ HRESULT GetMediaType(CMediaType* pmt);
};
[uuid("87864E0F-7073-4E39-B802-143DE0ED4964")]
class CSubtitleSourceUTF8 : public CSubtitleSource
{
public:
- CSubtitleSourceUTF8(LPUNKNOWN lpunk, HRESULT* phr);
+ CSubtitleSourceUTF8(LPUNKNOWN lpunk, HRESULT* phr);
- HRESULT GetMediaType(CMediaType* pmt);
+ HRESULT GetMediaType(CMediaType* pmt);
};
[uuid("18316B1A-5877-4CC4-85FD-EDE65CD489EC")]
class CSubtitleSourceSSA : public CSubtitleSource
{
public:
- CSubtitleSourceSSA(LPUNKNOWN lpunk, HRESULT* phr);
+ CSubtitleSourceSSA(LPUNKNOWN lpunk, HRESULT* phr);
- HRESULT GetMediaType(CMediaType* pmt);
+ HRESULT GetMediaType(CMediaType* pmt);
};
[uuid("416782BC-1D87-48C0-8F65-F113A5CB8E15")]
class CSubtitleSourceASS : public CSubtitleSource
{
public:
- CSubtitleSourceASS(LPUNKNOWN lpunk, HRESULT* phr);
+ CSubtitleSourceASS(LPUNKNOWN lpunk, HRESULT* phr);
- HRESULT GetMediaType(CMediaType* pmt);
+ HRESULT GetMediaType(CMediaType* pmt);
};
[uuid("D7215AFC-DFE6-483B-9AF3-6BBECFF14CF4")]
class CSubtitleSourceUSF : public CSubtitleSource
{
public:
- CSubtitleSourceUSF(LPUNKNOWN lpunk, HRESULT* phr);
+ CSubtitleSourceUSF(LPUNKNOWN lpunk, HRESULT* phr);
- HRESULT GetMediaType(CMediaType* pmt);
+ HRESULT GetMediaType(CMediaType* pmt);
};
[uuid("932E75D4-BBD4-4A0F-9071-6728FBDC4C98")]
class CSubtitleSourcePreview : public CSubtitleSource
{
public:
- CSubtitleSourcePreview(LPUNKNOWN lpunk, HRESULT* phr);
+ CSubtitleSourcePreview(LPUNKNOWN lpunk, HRESULT* phr);
- HRESULT GetMediaType(CMediaType* pmt);
+ HRESULT GetMediaType(CMediaType* pmt);
};
[uuid("CF0D7280-527D-415E-BA02-56017484D73E")]
class CSubtitleSourceARGB : public CSubtitleSource
{
public:
- CSubtitleSourceARGB(LPUNKNOWN lpunk, HRESULT* phr);
+ CSubtitleSourceARGB(LPUNKNOWN lpunk, HRESULT* phr);
- HRESULT GetMediaType(CMediaType* pmt);
+ HRESULT GetMediaType(CMediaType* pmt);
};
diff --git a/src/filters/source/SubtitleSource/resource.h b/src/filters/source/SubtitleSource/resource.h
index fb6ab9443..2dcb23529 100644
--- a/src/filters/source/SubtitleSource/resource.h
+++ b/src/filters/source/SubtitleSource/resource.h
@@ -3,7 +3,7 @@
// Used by subtitlesource.rc
// Next default values for new objects
-//
+//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
diff --git a/src/filters/source/SubtitleSource/stdafx.cpp b/src/filters/source/SubtitleSource/stdafx.cpp
index f08539cb9..a51424de6 100644
--- a/src/filters/source/SubtitleSource/stdafx.cpp
+++ b/src/filters/source/SubtitleSource/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
diff --git a/src/filters/source/SubtitleSource/stdafx.h b/src/filters/source/SubtitleSource/stdafx.h
index c35359c38..a9f666228 100644
--- a/src/filters/source/SubtitleSource/stdafx.h
+++ b/src/filters/source/SubtitleSource/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/