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:
authorUnderground78 <underground78@users.sourceforge.net>2013-06-23 22:46:36 +0400
committerUnderground78 <underground78@users.sourceforge.net>2013-06-29 23:56:22 +0400
commitf46c1fd78e595b889bb27148a986cdbd0e4913c0 (patch)
treefbd90a5b738081dc615b1083382907cb228e6b3a /src/filters/transform/Mpeg2DecFilter
parent51e719b03f2e1ace5bf49b1512b340f278cb586e (diff)
Remove now deprecated filters.
Diffstat (limited to 'src/filters/transform/Mpeg2DecFilter')
-rw-r--r--src/filters/transform/Mpeg2DecFilter/IMpeg2DecFilter.h65
-rw-r--r--src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.cpp2439
-rw-r--r--src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.def5
-rw-r--r--src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.h329
-rw-r--r--src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.rc124
-rw-r--r--src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.vcxproj277
-rw-r--r--src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.vcxproj.filters83
-rw-r--r--src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.cpp239
-rw-r--r--src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.h88
-rw-r--r--src/filters/transform/Mpeg2DecFilter/attributes.h44
-rw-r--r--src/filters/transform/Mpeg2DecFilter/idct_mmx.objbin10091 -> 0 bytes
-rw-r--r--src/filters/transform/Mpeg2DecFilter/idct_sse2.cpp322
-rw-r--r--src/filters/transform/Mpeg2DecFilter/libmpeg2.cpp3743
-rw-r--r--src/filters/transform/Mpeg2DecFilter/libmpeg2.h402
-rw-r--r--src/filters/transform/Mpeg2DecFilter/mc_sse2.cpp483
-rw-r--r--src/filters/transform/Mpeg2DecFilter/motion_comp_mmx.objbin8998 -> 0 bytes
-rw-r--r--src/filters/transform/Mpeg2DecFilter/resource.h27
-rw-r--r--src/filters/transform/Mpeg2DecFilter/stdafx.cpp22
-rw-r--r--src/filters/transform/Mpeg2DecFilter/stdafx.h27
19 files changed, 0 insertions, 8719 deletions
diff --git a/src/filters/transform/Mpeg2DecFilter/IMpeg2DecFilter.h b/src/filters/transform/Mpeg2DecFilter/IMpeg2DecFilter.h
deleted file mode 100644
index 04580c72c..000000000
--- a/src/filters/transform/Mpeg2DecFilter/IMpeg2DecFilter.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * (C) 2003-2006 Gabest
- * (C) 2006-2013 see Authors.txt
- *
- * This file is part of MPC-HC.
- *
- * MPC-HC 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 3 of the License, or
- * (at your option) any later version.
- *
- * MPC-HC 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 this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#pragma once
-
-typedef enum {
- DIAuto,
- DIWeave,
- DIBlend,
- DIBob,
- DIFieldShift,
- DIELA
-} ditype;
-
-interface __declspec(uuid("0ABEAA65-0317-47B9-AE1D-D9EA905AFD25"))
-IMpeg2DecFilter :
-public IUnknown {
- STDMETHOD(SetDeinterlaceMethod(ditype di)) PURE;
- STDMETHOD_(ditype, GetDeinterlaceMethod()) PURE;
- // Brightness: -255.0 to 255.0, default 0.0
- // Contrast: 0.0 to 10.0, default 1.0
- // Hue: -180.0 to +180.0, default 0.0
- // Saturation: 0.0 to 10.0, default 1.0
-
- STDMETHOD(SetBrightness(float brightness)) PURE;
- STDMETHOD(SetContrast(float contrast)) PURE;
- STDMETHOD(SetHue(float hue)) PURE;
- STDMETHOD(SetSaturation(float saturation)) PURE;
- STDMETHOD_(float, GetBrightness()) PURE;
- STDMETHOD_(float, GetContrast()) PURE;
- STDMETHOD_(float, GetHue()) PURE;
- STDMETHOD_(float, GetSaturation()) PURE;
-
- STDMETHOD(EnableForcedSubtitles(bool fEnable)) PURE;
- STDMETHOD_(bool, IsForcedSubtitlesEnabled()) PURE;
-
- STDMETHOD(EnablePlanarYUV(bool fEnable)) PURE;
- STDMETHOD_(bool, IsPlanarYUVEnabled()) PURE;
-
- STDMETHOD(EnableInterlaced(bool fEnable)) PURE;
- STDMETHOD_(bool, IsInterlacedEnabled()) PURE;
-
- STDMETHOD(EnableReadARFromStream(bool fEnable)) PURE;
- STDMETHOD_(bool, IsReadARFromStreamEnabled()) PURE;
-
- STDMETHOD(Apply()) PURE;
-};
diff --git a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.cpp b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.cpp
deleted file mode 100644
index c072f9078..000000000
--- a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.cpp
+++ /dev/null
@@ -1,2439 +0,0 @@
-/*
- * (C) 2003-2006 Gabest
- * (C) 2006-2013 see Authors.txt
- *
- * This file is part of MPC-HC.
- *
- * MPC-HC 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 3 of the License, or
- * (at your option) any later version.
- *
- * MPC-HC 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 this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "stdafx.h"
-#include <math.h>
-#include <atlbase.h>
-#include <ks.h>
-#include <ksmedia.h>
-#include "libmpeg2.h"
-#include "Mpeg2DecFilter.h"
-
-#include <xmmintrin.h>
-#include <emmintrin.h>
-
-#include "../../../DSUtil/DSUtil.h"
-#include "../../../DSUtil/MediaTypes.h"
-#include "../../../DSUtil/GolombBuffer.h"
-
-#ifdef STANDALONE_FILTER
-#include <InitGuid.h>
-#endif
-#include "moreuuids.h"
-#include "IFilterVersion.h"
-#include "detours/detours.h"
-
-#define EPSILON 1e-4
-
-#ifdef STANDALONE_FILTER
-
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
- {&MEDIATYPE_DVD_ENCRYPTED_PACK, &MEDIASUBTYPE_MPEG2_VIDEO},
- {&MEDIATYPE_MPEG2_PACK, &MEDIASUBTYPE_MPEG2_VIDEO},
- {&MEDIATYPE_MPEG2_PES, &MEDIASUBTYPE_MPEG2_VIDEO},
- {&MEDIATYPE_Video, &MEDIASUBTYPE_MPEG2_VIDEO},
- {&MEDIATYPE_Video, &MEDIASUBTYPE_MPG2},
-#ifndef MPEG2ONLY
- {&MEDIATYPE_Video, &MEDIASUBTYPE_MPEG1Packet},
- {&MEDIATYPE_Video, &MEDIASUBTYPE_MPEG1Payload},
-#endif
-};
-
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
- {&MEDIATYPE_Video, &MEDIASUBTYPE_IYUV},
-};
-
-const AMOVIESETUP_PIN sudpPins[] = {
- {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, nullptr, _countof(sudPinTypesIn), sudPinTypesIn},
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, nullptr, _countof(sudPinTypesOut), sudPinTypesOut}
-};
-
-const AMOVIESETUP_FILTER sudFilter[] = {
- {&__uuidof(CMpeg2DecFilter), Mpeg2DecFilterName, 0x00600001, _countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
-};
-
-CFactoryTemplate g_Templates[] = {
- {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CMpeg2DecFilter>, nullptr, &sudFilter[0]},
- {L"CMpeg2DecPropertyPage", &__uuidof(CMpeg2DecSettingsWnd), CreateInstance<CInternalPropertyPageTempl<CMpeg2DecSettingsWnd>>},
-};
-
-int g_cTemplates = _countof(g_Templates);
-
-STDAPI DllRegisterServer()
-{
- return AMovieDllRegisterServer2(TRUE);
-}
-
-STDAPI DllUnregisterServer()
-{
- return AMovieDllRegisterServer2(FALSE);
-}
-
-//
-
-BOOL (__stdcall* Real_IsDebuggerPresent)()
- = IsDebuggerPresent;
-
-LONG(__stdcall* Real_ChangeDisplaySettingsExA)(LPCSTR a0,
- LPDEVMODEA a1,
- HWND a2,
- DWORD a3,
- LPVOID a4)
- = ChangeDisplaySettingsExA;
-
-LONG(__stdcall* Real_ChangeDisplaySettingsExW)(LPCWSTR a0,
- LPDEVMODEW a1,
- HWND a2,
- DWORD a3,
- LPVOID a4)
- = ChangeDisplaySettingsExW;
-
-
-BOOL WINAPI Mine_IsDebuggerPresent()
-{
- TRACE(_T("Oops, somebody was trying to be naughty! (called IsDebuggerPresent)\n"));
- return FALSE;
-}
-
-LONG WINAPI Mine_ChangeDisplaySettingsEx(LONG ret, DWORD dwFlags, LPVOID lParam)
-{
- if (dwFlags & CDS_VIDEOPARAMETERS) {
- VIDEOPARAMETERS* vp = (VIDEOPARAMETERS*)lParam;
-
- if (vp->Guid == GUIDFromCString(_T("{02C62061-1097-11d1-920F-00A024DF156E}"))
- && (vp->dwFlags & VP_FLAGS_COPYPROTECT)) {
- if (vp->dwCommand == VP_COMMAND_GET) {
- if ((vp->dwTVStandard & VP_TV_STANDARD_WIN_VGA) && vp->dwTVStandard != VP_TV_STANDARD_WIN_VGA) {
- TRACE(_T("Ooops, tv-out enabled? macrovision checks suck...\n"));
- vp->dwTVStandard = VP_TV_STANDARD_WIN_VGA;
- }
- } else if (vp->dwCommand == VP_COMMAND_SET) {
- TRACE(_T("Ooops, as I already told ya, no need for any macrovision bs here\n"));
- return 0;
- }
- }
- }
-
- return ret;
-}
-LONG WINAPI Mine_ChangeDisplaySettingsExA(LPCSTR lpszDeviceName, LPDEVMODEA lpDevMode, HWND hwnd, DWORD dwFlags, LPVOID lParam)
-{
- return Mine_ChangeDisplaySettingsEx(Real_ChangeDisplaySettingsExA(lpszDeviceName, lpDevMode, hwnd, dwFlags, lParam), dwFlags, lParam);
-}
-LONG WINAPI Mine_ChangeDisplaySettingsExW(LPCWSTR lpszDeviceName, LPDEVMODEW lpDevMode, HWND hwnd, DWORD dwFlags, LPVOID lParam)
-{
- return Mine_ChangeDisplaySettingsEx(Real_ChangeDisplaySettingsExW(lpszDeviceName, lpDevMode, hwnd, dwFlags, lParam), dwFlags, lParam);
-}
-
-//
-
-#include "../../FilterApp.h"
-
-class CMpeg2DecFilterApp : public CFilterApp
-{
-public:
- BOOL InitInstance() {
- long lError;
-
- if (!__super::InitInstance()) {
- return FALSE;
- }
-
- DetourRestoreAfterWith();
- DetourTransactionBegin();
- DetourUpdateThread(GetCurrentThread());
-
- DetourAttach(&(PVOID&)Real_IsDebuggerPresent, (PVOID)Mine_IsDebuggerPresent);
- DetourAttach(&(PVOID&)Real_ChangeDisplaySettingsExA, (PVOID)Mine_ChangeDisplaySettingsExA);
- DetourAttach(&(PVOID&)Real_ChangeDisplaySettingsExW, (PVOID)Mine_ChangeDisplaySettingsExW);
-
- lError = DetourTransactionCommit();
- ASSERT(lError == NOERROR);
-
- return TRUE;
- }
-};
-
-CMpeg2DecFilterApp theApp;
-
-#endif
-
-//
-// CMpeg2DecFilter
-//
-
-CMpeg2DecFilter::CMpeg2DecFilter(LPUNKNOWN lpunk, HRESULT* phr)
- : CBaseVideoFilter(NAME("CMpeg2DecFilter"), lpunk, phr, __uuidof(this), 1)
- , m_fWaitForKeyFrame(true)
- , m_fInitializedBuffer(true)
-{
- delete m_pInput;
- // delete m_pOutput;
-
- if (FAILED(*phr)) {
- return;
- }
-
- m_pInput = DEBUG_NEW CMpeg2DecInputPin(this, phr, L"Video");
- if (!m_pInput) {
- *phr = E_OUTOFMEMORY;
- }
- if (FAILED(*phr)) {
- return;
- }
-
- // m_pOutput = DEBUG_NEW CMpeg2DecOutputPin(this, phr, L"Output");
- // if (!m_pOutput) *phr = E_OUTOFMEMORY;
- // if (FAILED(*phr)) return;
-
- m_pSubpicInput = DEBUG_NEW CSubpicInputPin(this, phr);
- if (!m_pSubpicInput) {
- *phr = E_OUTOFMEMORY;
- }
- if (FAILED(*phr)) {
- return;
- }
-
- m_pClosedCaptionOutput = DEBUG_NEW CClosedCaptionOutputPin(this, m_pLock, phr);
- if (!m_pClosedCaptionOutput) {
- *phr = E_OUTOFMEMORY;
- }
- if (FAILED(*phr)) {
- return;
- }
-
- SetDeinterlaceMethod(DIAuto);
- SetBrightness(0.0f);
- SetContrast(1.0f);
- SetHue(0.0f);
- SetSaturation(1.0f);
- EnableForcedSubtitles(true);
- EnablePlanarYUV(true);
- EnableInterlaced(false);
- EnableReadARFromStream(true);
-
-#ifdef STANDALONE_FILTER
- CRegKey key;
- if (ERROR_SUCCESS == key.Open(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPEG Video Decoder"), KEY_READ)) {
- DWORD dw;
- if (ERROR_SUCCESS == key.QueryDWORDValue(_T("DeinterlaceMethod"), dw)) {
- SetDeinterlaceMethod((ditype)dw);
- }
- if (ERROR_SUCCESS == key.QueryDWORDValue(_T("Brightness"), dw)) {
- SetBrightness(*(float*)&dw);
- }
- if (ERROR_SUCCESS == key.QueryDWORDValue(_T("Contrast"), dw)) {
- SetContrast(*(float*)&dw);
- }
- if (ERROR_SUCCESS == key.QueryDWORDValue(_T("Hue"), dw)) {
- SetHue(*(float*)&dw);
- }
- if (ERROR_SUCCESS == key.QueryDWORDValue(_T("Saturation"), dw)) {
- SetSaturation(*(float*)&dw);
- }
- if (ERROR_SUCCESS == key.QueryDWORDValue(_T("ForcedSubtitles"), dw)) {
- EnableForcedSubtitles(!!dw);
- }
- if (ERROR_SUCCESS == key.QueryDWORDValue(_T("PlanarYUV"), dw)) {
- EnablePlanarYUV(!!dw);
- }
- if (ERROR_SUCCESS == key.QueryDWORDValue(_T("Interlaced"), dw)) {
- EnableInterlaced(!!dw);
- }
- if (ERROR_SUCCESS == key.QueryDWORDValue(_T("ReadARFromStream"), dw)) {
- EnableReadARFromStream(!!dw);
- }
- }
-#else
- DWORD dw;
- dw = AfxGetApp()->GetProfileInt(_T("Filters\\MPEG Video Decoder"), _T("DeinterlaceMethod"), m_ditype);
- SetDeinterlaceMethod((ditype)dw);
- dw = AfxGetApp()->GetProfileInt(_T("Filters\\MPEG Video Decoder"), _T("Brightness"), *(DWORD*)&m_bright);
- SetBrightness(*(float*)&dw);
- dw = AfxGetApp()->GetProfileInt(_T("Filters\\MPEG Video Decoder"), _T("Contrast"), *(DWORD*)&m_cont);
- SetContrast(*(float*)&dw);
- dw = AfxGetApp()->GetProfileInt(_T("Filters\\MPEG Video Decoder"), _T("Hue"), *(DWORD*)&m_hue);
- SetHue(*(float*)&dw);
- dw = AfxGetApp()->GetProfileInt(_T("Filters\\MPEG Video Decoder"), _T("Saturation"), *(DWORD*)&m_sat);
- SetSaturation(*(float*)&dw);
- dw = AfxGetApp()->GetProfileInt(_T("Filters\\MPEG Video Decoder"), _T("ForcedSubtitles"), m_fForcedSubs);
- EnableForcedSubtitles(!!dw);
- dw = AfxGetApp()->GetProfileInt(_T("Filters\\MPEG Video Decoder"), _T("PlanarYUV"), m_fPlanarYUV);
- EnablePlanarYUV(!!dw);
- dw = AfxGetApp()->GetProfileInt(_T("Filters\\MPEG Video Decoder"), _T("Interlaced"), m_fInterlaced);
- EnableInterlaced(!!dw);
- dw = AfxGetApp()->GetProfileInt(_T("Filters\\MPEG Video Decoder"), _T("ReadARFromStream"), m_bReadARFromStream);
- EnableReadARFromStream(!!dw);
-
-#endif
-
- m_rate.Rate = 10000;
- m_rate.StartTime = 0;
-
- m_par.SetSize(1, 1);
-}
-
-CMpeg2DecFilter::~CMpeg2DecFilter()
-{
- delete m_pSubpicInput;
- delete m_pClosedCaptionOutput;
-}
-
-STDMETHODIMP CMpeg2DecFilter::Apply()
-{
-#ifdef STANDALONE_FILTER
- CRegKey key;
- if (ERROR_SUCCESS == key.Create(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPEG Video Decoder"))) {
- key.SetDWORDValue(_T("DeinterlaceMethod"), m_ditype);
- key.SetDWORDValue(_T("Brightness"), *(DWORD*)&m_bright);
- key.SetDWORDValue(_T("Contrast"), *(DWORD*)&m_cont);
- key.SetDWORDValue(_T("Hue"), *(DWORD*)&m_hue);
- key.SetDWORDValue(_T("Saturation"), *(DWORD*)&m_sat);
- key.SetDWORDValue(_T("ForcedSubtitles"), m_fForcedSubs);
- key.SetDWORDValue(_T("PlanarYUV"), m_fPlanarYUV);
- key.SetDWORDValue(_T("Interlaced"), m_fInterlaced);
- key.SetDWORDValue(_T("ReadARFromStream"), m_bReadARFromStream);
- }
-#else
- AfxGetApp()->WriteProfileInt(_T("Filters\\MPEG Video Decoder"), _T("DeinterlaceMethod"), m_ditype);
- AfxGetApp()->WriteProfileInt(_T("Filters\\MPEG Video Decoder"), _T("Brightness"), *(DWORD*)&m_bright);
- AfxGetApp()->WriteProfileInt(_T("Filters\\MPEG Video Decoder"), _T("Contrast"), *(DWORD*)&m_cont);
- AfxGetApp()->WriteProfileInt(_T("Filters\\MPEG Video Decoder"), _T("Hue"), *(DWORD*)&m_hue);
- AfxGetApp()->WriteProfileInt(_T("Filters\\MPEG Video Decoder"), _T("Saturation"), *(DWORD*)&m_sat);
- AfxGetApp()->WriteProfileInt(_T("Filters\\MPEG Video Decoder"), _T("ForcedSubtitles"), m_fForcedSubs);
- AfxGetApp()->WriteProfileInt(_T("Filters\\MPEG Video Decoder"), _T("PlanarYUV"), m_fPlanarYUV);
- AfxGetApp()->WriteProfileInt(_T("Filters\\MPEG Video Decoder"), _T("Interlaced"), m_fInterlaced);
- AfxGetApp()->WriteProfileInt(_T("Filters\\MPEG Video Decoder"), _T("ReadARFromStream"), m_bReadARFromStream);
-#endif
-
- return S_OK;
-}
-
-void CMpeg2DecFilter::GetOutputSize(int& w, int& h, int& arx, int& ary, int& RealWidth, int& RealHeight)
-{
- w = m_dec->m_info.m_sequence->picture_width;
- h = m_dec->m_info.m_sequence->picture_height;
-}
-
-STDMETHODIMP CMpeg2DecFilter::NonDelegatingQueryInterface(REFIID riid, void** ppv)
-{
- return
- QI(IMpeg2DecFilter)
- QI(ISpecifyPropertyPages)
- QI(ISpecifyPropertyPages2)
- __super::NonDelegatingQueryInterface(riid, ppv);
-}
-
-int CMpeg2DecFilter::GetPinCount()
-{
- return 4;
-}
-
-CBasePin* CMpeg2DecFilter::GetPin(int n)
-{
- switch (n) {
- case 0:
- return m_pInput;
- case 1:
- return m_pOutput;
- case 2:
- return m_pSubpicInput;
- case 3:
- return m_pClosedCaptionOutput;
- }
- return nullptr;
-}
-
-HRESULT CMpeg2DecFilter::EndOfStream()
-{
- CAutoLock cAutoLock(&m_csReceive);
- m_pClosedCaptionOutput->EndOfStream();
- return __super::EndOfStream();
-}
-
-HRESULT CMpeg2DecFilter::BeginFlush()
-{
- m_pClosedCaptionOutput->DeliverBeginFlush();
- return __super::BeginFlush();
-}
-
-HRESULT CMpeg2DecFilter::EndFlush()
-{
- m_pClosedCaptionOutput->DeliverEndFlush();
- return __super::EndFlush();
-}
-
-HRESULT CMpeg2DecFilter::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
-{
- CAutoLock cAutoLock(&m_csReceive);
- m_pClosedCaptionOutput->DeliverNewSegment(tStart, tStop, dRate);
- m_fDropFrames = false;
- return __super::NewSegment(tStart, tStop, dRate);
-}
-
-void CMpeg2DecFilter::InputTypeChanged()
-{
- CAutoLock cAutoLock(&m_csReceive);
-
- TRACE(_T("ResetMpeg2Decoder()\n"));
-
- for (int i = 0; i < _countof(m_dec->m_pictures); i++) {
- m_dec->m_pictures[i].rtStart = m_dec->m_pictures[i].rtStop = _I64_MIN + 1;
- m_dec->m_pictures[i].fDelivered = false;
- m_dec->m_pictures[i].flags &= ~PIC_MASK_CODING_TYPE;
- }
-
- const CMediaType& mt = m_pInput->CurrentMediaType();
-
- BYTE* pSequenceHeader = nullptr;
- DWORD cbSequenceHeader = 0;
-
- if (mt.formattype == FORMAT_MPEGVideo) {
- pSequenceHeader = ((MPEG1VIDEOINFO*)mt.Format())->bSequenceHeader;
- cbSequenceHeader = ((MPEG1VIDEOINFO*)mt.Format())->cbSequenceHeader;
- } else if (mt.formattype == FORMAT_MPEG2_VIDEO) {
- pSequenceHeader = (BYTE*)((MPEG2VIDEOINFO*)mt.Format())->dwSequenceHeader;
- cbSequenceHeader = ((MPEG2VIDEOINFO*)mt.Format())->cbSequenceHeader;
- }
-
- m_dec->mpeg2_close();
- m_dec->mpeg2_init();
-
- m_dec->mpeg2_buffer(pSequenceHeader, pSequenceHeader + cbSequenceHeader);
-
- m_fWaitForKeyFrame = true;
-
- m_fFilm = false;
- m_fb.flags = 0;
-}
-
-void CMpeg2DecFilter::SetDeinterlaceMethod()
-{
- ASSERT(m_dec->m_info.m_sequence);
- ASSERT(m_dec->m_info.m_display_picture);
-
- DWORD seqflags = m_dec->m_info.m_sequence->flags;
- DWORD oldflags = m_fb.flags;
- DWORD newflags = m_dec->m_info.m_display_picture->flags;
-
- if (!(seqflags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)
- && !(oldflags & PIC_FLAG_REPEAT_FIRST_FIELD)
- && (newflags & PIC_FLAG_PROGRESSIVE_FRAME)) {
- if (!m_fFilm && (newflags & PIC_FLAG_REPEAT_FIRST_FIELD)) {
- TRACE(_T("m_fFilm = true\n"));
- m_fFilm = true;
- } else if (m_fFilm && !(newflags & PIC_FLAG_REPEAT_FIRST_FIELD)) {
- TRACE(_T("m_fFilm = false\n"));
- m_fFilm = false;
- }
- }
-
- const CMediaType& mt = m_pOutput->CurrentMediaType();
-
- if (mt.formattype == FORMAT_VideoInfo2 && (((VIDEOINFOHEADER2*)mt.pbFormat)->dwInterlaceFlags & AMINTERLACE_IsInterlaced)) {
- m_fb.di = DIWeave;
- } else {
- m_fb.di = GetDeinterlaceMethod();
-
- if (m_fb.di == DIAuto || m_fb.di != DIWeave && m_fb.di != DIBlend && m_fb.di != DIBob && m_fb.di != DIFieldShift && m_fb.di != DIELA) {
- if (seqflags & SEQ_FLAG_PROGRESSIVE_SEQUENCE) {
- m_fb.di = DIWeave; // hurray!
- } else if (m_fFilm) {
- m_fb.di = DIWeave; // we are lucky
- } else if (!(m_fb.flags & PIC_FLAG_PROGRESSIVE_FRAME)) {
- m_fb.di = DIBlend; // ok, clear thing
- } else
- // big trouble here, the progressive_frame bit is not reliable :'(
- // frames without temporal field diffs can be only detected when ntsc
- // uses the repeat field flag (signaled with m_fFilm), if it's not set
- // or we have pal then we might end up blending the fields unnecessarily...
- {
- m_fb.di = DIBlend;
- }
- }
- }
-
- m_fb.flags = newflags;
-}
-
-void CMpeg2DecFilter::SetTypeSpecificFlags(IMediaSample* pMS)
-{
- if (CComQIPtr<IMediaSample2> pMS2 = pMS) {
- AM_SAMPLE2_PROPERTIES props;
- if (SUCCEEDED(pMS2->GetProperties(sizeof(props), (BYTE*)&props))) {
- props.dwTypeSpecificFlags &= ~0x7f;
-
- const CMediaType& mt = m_pOutput->CurrentMediaType();
- if (mt.formattype == FORMAT_VideoInfo2 && (((VIDEOINFOHEADER2*)mt.pbFormat)->dwInterlaceFlags & AMINTERLACE_IsInterlaced)) {
- // props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_WEAVE;
-
- if (m_dec->m_info.m_sequence->flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE) {
- props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_WEAVE;
- }
-
- if (m_fb.flags & PIC_FLAG_TOP_FIELD_FIRST) {
- props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_FIELD1FIRST;
- }
- if (m_fb.flags & PIC_FLAG_REPEAT_FIRST_FIELD) {
- props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_REPEAT_FIELD;
- }
-
- if ((m_fb.flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I) {
- props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_I_SAMPLE;
- }
- if ((m_fb.flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P) {
- props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_P_SAMPLE;
- }
- if ((m_fb.flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B) {
- props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_B_SAMPLE;
- }
- }
-
- pMS2->SetProperties(sizeof(props), (BYTE*)&props);
- }
- }
-}
-
-HRESULT CMpeg2DecFilter::Transform(IMediaSample* pIn)
-{
- HRESULT hr;
-
- BYTE* pDataIn = nullptr;
- if (FAILED(hr = pIn->GetPointer(&pDataIn))) {
- return hr;
- }
-
- long len = pIn->GetActualDataLength();
-
- (static_cast<CDeCSSInputPin*>(m_pInput))->StripPacket(pDataIn, len);
-
- if (pIn->IsDiscontinuity() == S_OK) {
- InputTypeChanged();
- }
-
- REFERENCE_TIME rtStart = _I64_MIN, rtStop = _I64_MIN;
- hr = pIn->GetTime(&rtStart, &rtStop);
- if (FAILED(hr)) {
- rtStart = rtStop = _I64_MIN;
- }
-
- while (len >= 0) {
- mpeg2_state_t state = m_dec->mpeg2_parse();
-#ifndef _WIN64
- __asm emms; // this one is missing somewhere in the precompiled mmx obj files
-#endif
- switch (state) {
- case STATE_BUFFER:
- if (len > 0) {
- m_dec->mpeg2_buffer(pDataIn, pDataIn + len);
- len = 0;
- } else {
- len = -1;
- }
- break;
- case STATE_INVALID:
- TRACE(_T("*** STATE_INVALID\n"));
- break;
- case STATE_GOP:
- m_pClosedCaptionOutput->Deliver(m_dec->m_info.m_user_data, m_dec->m_info.m_user_data_len);
- break;
- case STATE_SEQUENCE:
- m_AvgTimePerFrame = m_dec->m_info.m_sequence->frame_period
- ? 10i64 * m_dec->m_info.m_sequence->frame_period / 27
- : ((VIDEOINFOHEADER*)m_pInput->CurrentMediaType().Format())->AvgTimePerFrame;
- break;
- case STATE_PICTURE:
- m_dec->m_picture->rtStart = rtStart;
- rtStart = _I64_MIN;
- m_dec->m_picture->fDelivered = false;
- m_dec->mpeg2_skip(m_fDropFrames && (m_dec->m_picture->flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B);
- break;
- case STATE_SLICE:
- case STATE_END: {
- mpeg2_picture_t* picture = m_dec->m_info.m_display_picture;
- mpeg2_fbuf_t* fbuf = m_dec->m_info.m_display_fbuf;
-
- if (picture && !(picture->flags & PIC_FLAG_SKIP) && fbuf) {
- ASSERT(!picture->fDelivered);
-
- picture->fDelivered = true;
-
- // frame buffer
-
- int w = m_dec->m_info.m_sequence->picture_width;
- int h = m_dec->m_info.m_sequence->picture_height;
- int pitch = (m_dec->m_info.m_sequence->width + 31) & ~31;
-
- if (m_fb.w != w || m_fb.h != h || m_fb.pitch != pitch) {
- m_fb.Alloc(w, h, pitch);
- m_fInitializedBuffer = false;
- }
-
- // start - end
-
- m_fb.rtStart = picture->rtStart;
- if (m_fb.rtStart == _I64_MIN) {
- m_fb.rtStart = m_fb.rtStop;
- }
- m_fb.rtStop = m_fb.rtStart + m_AvgTimePerFrame * picture->nb_fields / (m_dec->m_info.m_display_picture_2nd ? 1 : 2);
-
- REFERENCE_TIME rtStart2 = m_fb.rtStart;
- REFERENCE_TIME rtStop2 = m_fb.rtStop;
- UNREFERENCED_PARAMETER(rtStart2);
- UNREFERENCED_PARAMETER(rtStop2);
-
- //
-
- SetDeinterlaceMethod();
- UpdateAspectRatio();
-
- hr = DeliverFast();
- if (hr != S_OK) {
- hr = DeliverNormal();
- }
- if (hr != S_OK) {
- return hr;
- }
- if (hr == S_OK && !m_fWaitForKeyFrame) {
- m_fInitializedBuffer = true;
- }
- }
- }
- break;
- default:
- break;
- }
- }
-
- return S_OK;
-}
-
-bool CMpeg2DecFilter::IsVideoInterlaced()
-{
- return IsInterlacedEnabled();
-}
-
-void CMpeg2DecFilter::UpdateAspectRatio()
-{
- if (m_bReadARFromStream && ((unsigned int)m_par.cx != m_dec->m_info.m_sequence->pixel_width || (unsigned int)m_par.cy != m_dec->m_info.m_sequence->pixel_height)) {
- m_par.cx = m_dec->m_info.m_sequence->pixel_width;
- m_par.cy = m_dec->m_info.m_sequence->pixel_height;
- CSize dar(m_dec->m_info.m_sequence->picture_width * m_par.cx,
- m_dec->m_info.m_sequence->picture_height * m_par.cy);
- int gcd = GCD(dar.cx, dar.cy);
- if (gcd > 1) {
- dar.cx /= gcd;
- dar.cy /= gcd;
- }
- SetAspect(dar);
- }
-}
-
-HRESULT CMpeg2DecFilter::DeliverFast()
-{
- HRESULT hr;
-
- CAutoLock cAutoLock(&m_csReceive);
-
- mpeg2_fbuf_t* fbuf = m_dec->m_info.m_display_fbuf;
- if (!fbuf) {
- return S_FALSE;
- }
-
- {
-
- CAutoLock cAutoLock2(&m_csProps);
-
- if (GetCLSID(m_pInput->GetConnected()) == CLSID_DVDNavigator
- || m_pSubpicInput->HasAnythingToRender(m_fb.rtStart)
- || fabs(m_bright) > EPSILON || fabs(m_cont - 1.0) > EPSILON
- || fabs(m_hue) > EPSILON || fabs(m_sat - 1.0) > EPSILON) {
- return S_FALSE;
- }
- }
-
- if ((m_fb.flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I) {
- m_fWaitForKeyFrame = false;
- }
-
- if (m_fb.rtStart < 0 || m_fWaitForKeyFrame) {
- return S_OK;
- }
-
- const CMediaType& mt = m_pOutput->CurrentMediaType();
-
- if (mt.subtype != MEDIASUBTYPE_I420 && mt.subtype != MEDIASUBTYPE_IYUV && mt.subtype != MEDIASUBTYPE_YV12) {
- return S_FALSE;
- }
-
- CComPtr<IMediaSample> pOut;
- BYTE* pDataOut = nullptr;
- if (FAILED(hr = GetDeliveryBuffer(m_fb.w, m_fb.h, &pOut))
- || FAILED(hr = pOut->GetPointer(&pDataOut))) {
- return hr;
- }
-
- if (mt.subtype != MEDIASUBTYPE_I420 && mt.subtype != MEDIASUBTYPE_IYUV && mt.subtype != MEDIASUBTYPE_YV12) {
- return S_FALSE;
- }
-
- BITMAPINFOHEADER bihOut;
- ExtractBIH(&mt, &bihOut);
-
- int w = bihOut.biWidth;
- int h = abs(bihOut.biHeight);
- int srcpitch = m_dec->m_info.m_sequence->width; // TODO (..+7)&~7; ?
- int dstpitch = bihOut.biWidth;
-
- BYTE* y = pDataOut;
- BYTE* u = y + dstpitch * h;
- BYTE* v = y + dstpitch * h * 5 / 4;
-
- if (bihOut.biCompression == '21VY') {
- BYTE* tmp = u;
- u = v;
- v = tmp;
- }
-
- if (m_fb.di == DIWeave) {
- BitBltFromI420ToI420(w, h, y, u, v, dstpitch, fbuf->buf[0], fbuf->buf[1], fbuf->buf[2], srcpitch);
- } else if (m_fb.di == DIBlend) {
- DeinterlaceBlend(y, fbuf->buf[0], w, h, dstpitch, srcpitch);
- DeinterlaceBlend(u, fbuf->buf[1], w / 2, h / 2, dstpitch / 2, srcpitch / 2);
- DeinterlaceBlend(v, fbuf->buf[2], w / 2, h / 2, dstpitch / 2, srcpitch / 2);
- } else { // TODO
- return S_FALSE;
- }
-
- if (h == 1088) {
- memset(y + dstpitch * (h - 8), 0xff, dstpitch * 8);
- memset(u + dstpitch * (h - 8) / 4, 0x80, dstpitch * 8 / 4);
- memset(v + dstpitch * (h - 8) / 4, 0x80, dstpitch * 8 / 4);
- }
-
- if (CMpeg2DecInputPin* pPin = dynamic_cast<CMpeg2DecInputPin*>(m_pInput)) {
- CAutoLock cAutoLock2(&pPin->m_csRateLock);
-
- if (m_rate.Rate != pPin->m_ratechange.Rate) {
- m_rate.Rate = pPin->m_ratechange.Rate;
- m_rate.StartTime = m_fb.rtStart;
- }
- }
-
- REFERENCE_TIME rtStart = m_fb.rtStart;
- REFERENCE_TIME rtStop = m_fb.rtStop;
-
- rtStart = m_rate.StartTime + (rtStart - m_rate.StartTime) * m_rate.Rate / 10000;
- rtStop = m_rate.StartTime + (rtStop - m_rate.StartTime) * m_rate.Rate / 10000;
-
- pOut->SetTime(&rtStart, &rtStop);
- pOut->SetMediaTime(nullptr, nullptr);
-
- //
-
- SetTypeSpecificFlags(pOut);
-
- //
-
- return m_pOutput->Deliver(pOut);
-}
-
-HRESULT CMpeg2DecFilter::DeliverNormal()
-{
- HRESULT hr = S_OK;
-
- CAutoLock cAutoLock(&m_csReceive);
-
- mpeg2_fbuf_t* fbuf = m_dec->m_info.m_display_fbuf;
- if (!fbuf) {
- return S_FALSE;
- }
-
- int w = m_fb.w;
- int h = m_fb.h;
- int spitch = m_dec->m_info.m_sequence->width; // TODO (..+7)&~7; ?
- int dpitch = m_fb.pitch;
-
- REFERENCE_TIME rtStart = m_fb.rtStart;
- REFERENCE_TIME rtStop = m_fb.rtStop;
-
- bool tff = !!(m_fb.flags & PIC_FLAG_TOP_FIELD_FIRST);
-
- // deinterlace
-
- if (m_fb.di == DIWeave) {
- BitBltFromI420ToI420(w, h, m_fb.buf[0], m_fb.buf[1], m_fb.buf[2], dpitch, fbuf->buf[0], fbuf->buf[1], fbuf->buf[2], spitch);
- } else if (m_fb.di == DIBlend) {
- DeinterlaceBlend(m_fb.buf[0], fbuf->buf[0], w, h, dpitch, spitch);
- DeinterlaceBlend(m_fb.buf[1], fbuf->buf[1], w / 2, h / 2, dpitch / 2, spitch / 2);
- DeinterlaceBlend(m_fb.buf[2], fbuf->buf[2], w / 2, h / 2, dpitch / 2, spitch / 2);
- } else if (m_fb.di == DIBob) {
- DeinterlaceBob(m_fb.buf[0], fbuf->buf[0], w, h, dpitch, spitch, tff);
- DeinterlaceBob(m_fb.buf[1], fbuf->buf[1], w / 2, h / 2, dpitch / 2, spitch / 2, tff);
- DeinterlaceBob(m_fb.buf[2], fbuf->buf[2], w / 2, h / 2, dpitch / 2, spitch / 2, tff);
-
- m_fb.rtStart = rtStart;
- m_fb.rtStop = (rtStart + rtStop) / 2;
- } else if (m_fb.di == DIFieldShift) {
- int soffset = tff ? 0 : spitch;
- int doffset = tff ? 0 : dpitch;
- BitBltFromRGBToRGB(w, h / 2, m_fb.buf[0] + doffset, dpitch * 2, 8, fbuf->buf[0] + soffset, spitch * 2, 8);
- BitBltFromRGBToRGB(w / 2, h / 4, m_fb.buf[1] + doffset / 2, dpitch, 8, fbuf->buf[1] + soffset / 2, spitch, 8);
- BitBltFromRGBToRGB(w / 2, h / 4, m_fb.buf[2] + doffset / 2, dpitch, 8, fbuf->buf[2] + soffset / 2, spitch, 8);
- } else if (m_fb.di == DIELA) {
- DeinterlaceELA(m_fb.buf[0], fbuf->buf[0], w, h, dpitch, spitch, tff);
- DeinterlaceELA(m_fb.buf[1], fbuf->buf[1], w / 2, h / 2, dpitch / 2, spitch / 2, tff);
- DeinterlaceELA(m_fb.buf[2], fbuf->buf[2], w / 2, h / 2, dpitch / 2, spitch / 2, tff);
- }
-
- // postproc
-
- ApplyBrContHueSat(m_fb.buf[0], m_fb.buf[1], m_fb.buf[2], w, h, dpitch);
-
- // deliver
-
- if (m_fb.di == DIWeave || m_fInitializedBuffer) {
- hr = Deliver(false);
- if (FAILED(hr)) {
- return hr;
- }
- }
-
- if (m_fb.di == DIBob) {
- DeinterlaceBob(m_fb.buf[0], fbuf->buf[0], w, h, dpitch, spitch, !tff);
- DeinterlaceBob(m_fb.buf[1], fbuf->buf[1], w / 2, h / 2, dpitch / 2, spitch / 2, !tff);
- DeinterlaceBob(m_fb.buf[2], fbuf->buf[2], w / 2, h / 2, dpitch / 2, spitch / 2, !tff);
-
- m_fb.rtStart = (rtStart + rtStop) / 2;
- m_fb.rtStop = rtStop;
-
- // postproc
-
- ApplyBrContHueSat(m_fb.buf[0], m_fb.buf[1], m_fb.buf[2], w, h, dpitch);
-
- // deliver
-
- hr = Deliver(false);
- } else if (m_fb.di == DIFieldShift) {
- int soffset = !tff ? 0 : spitch;
- int doffset = !tff ? 0 : dpitch;
- BitBltFromRGBToRGB(w, h / 2, m_fb.buf[0] + doffset, dpitch * 2, 8, fbuf->buf[0] + soffset, spitch * 2, 8);
- BitBltFromRGBToRGB(w / 2, h / 4, m_fb.buf[1] + doffset / 2, dpitch, 8, fbuf->buf[1] + soffset / 2, spitch, 8);
- BitBltFromRGBToRGB(w / 2, h / 4, m_fb.buf[2] + doffset / 2, dpitch, 8, fbuf->buf[2] + soffset / 2, spitch, 8);
- } else if (m_fb.di == DIELA) {
- DeinterlaceELA(m_fb.buf[0], fbuf->buf[0], w, h, dpitch, spitch, !tff);
- DeinterlaceELA(m_fb.buf[1], fbuf->buf[1], w / 2, h / 2, dpitch / 2, spitch / 2, !tff);
- DeinterlaceELA(m_fb.buf[2], fbuf->buf[2], w / 2, h / 2, dpitch / 2, spitch / 2, !tff);
- }
-
- if (!m_fInitializedBuffer) {
- hr = Deliver(false);
- }
-
- return hr;
-}
-
-HRESULT CMpeg2DecFilter::Deliver(bool fRepeatLast)
-{
- CAutoLock cAutoLock(&m_csReceive);
-
- if ((m_fb.flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I) {
- m_fWaitForKeyFrame = false;
- }
-
- if (m_fb.rtStart < 0 || m_fWaitForKeyFrame) {
- return S_OK;
- }
-
- HRESULT hr;
-
- CComPtr<IMediaSample> pOut;
- BYTE* pDataOut = nullptr;
- if (FAILED(hr = GetDeliveryBuffer(m_fb.w, m_fb.h, &pOut))
- || FAILED(hr = pOut->GetPointer(&pDataOut))) {
- return hr;
- }
-
- if (m_fb.h == 1088) {
- memset(m_fb.buf[0] + m_fb.w * (m_fb.h - 8), 0xff, m_fb.pitch * 8);
- memset(m_fb.buf[1] + m_fb.w * (m_fb.h - 8) / 4, 0x80, m_fb.pitch * 8 / 4);
- memset(m_fb.buf[2] + m_fb.w * (m_fb.h - 8) / 4, 0x80, m_fb.pitch * 8 / 4);
- }
-
- BYTE** buf = &m_fb.buf[0];
-
- if (m_pSubpicInput->HasAnythingToRender(m_fb.rtStart)) {
- BitBltFromI420ToI420(m_fb.w, m_fb.h,
- m_fb.buf[3], m_fb.buf[4], m_fb.buf[5], m_fb.pitch,
- m_fb.buf[0], m_fb.buf[1], m_fb.buf[2], m_fb.pitch);
-
- buf = &m_fb.buf[3];
-
- m_pSubpicInput->RenderSubpics(m_fb.rtStart, buf, m_fb.pitch, m_fb.h);
- }
-
- CopyBuffer(pDataOut, buf, (m_fb.w + 7)&~7, m_fb.h, m_fb.pitch, MEDIASUBTYPE_I420, !(m_fb.flags & PIC_FLAG_PROGRESSIVE_FRAME));
-
- //
-
- if (CMpeg2DecInputPin* pPin = dynamic_cast<CMpeg2DecInputPin*>(m_pInput)) {
- CAutoLock cAutoLock2(&pPin->m_csRateLock);
-
- if (m_rate.Rate != pPin->m_ratechange.Rate) {
- m_rate.Rate = pPin->m_ratechange.Rate;
- m_rate.StartTime = m_fb.rtStart;
- }
- }
-
- REFERENCE_TIME rtStart = m_fb.rtStart;
- REFERENCE_TIME rtStop = m_fb.rtStop;
-
- rtStart = m_rate.StartTime + (rtStart - m_rate.StartTime) * m_rate.Rate / 10000;
- rtStop = m_rate.StartTime + (rtStop - m_rate.StartTime) * m_rate.Rate / 10000;
-
- pOut->SetTime(&rtStart, &rtStop);
- pOut->SetMediaTime(nullptr, nullptr);
-
- //
-
- SetTypeSpecificFlags(pOut);
-
- //
-
- hr = m_pOutput->Deliver(pOut);
-
- return hr;
-}
-
-HRESULT CMpeg2DecFilter::CheckConnect(PIN_DIRECTION dir, IPin* pPin)
-{
- if (dir == PINDIR_OUTPUT) {
- if (GetCLSID(m_pInput->GetConnected()) == CLSID_DVDNavigator) {
- // one of these needed for dynamic format changes
-
- CLSID clsid = GetCLSID(pPin);
-
- DWORD ver = 0;
- if (CComQIPtr<IFilterVersion> pFV = GetFilterFromPin(pPin)) {
- ver = pFV->GetFilterVersion();
- }
-
- if (clsid != CLSID_OverlayMixer
- /*&& clsid != CLSID_OverlayMixer2*/
- && clsid != CLSID_VideoMixingRenderer
- && clsid != CLSID_VideoMixingRenderer9
- && clsid != CLSID_EnhancedVideoRenderer
- && clsid != GUIDFromCString(_T("{04FE9017-F873-410E-871E-AB91661A4EF7}")) // ffdshow
- && (clsid != GUIDFromCString(_T("{93A22E7A-5091-45ef-BA61-6DA26156A5D0}")) || ver < 0x0234) // dvobsub
- && (clsid != GUIDFromCString(_T("{9852A670-F845-491b-9BE6-EBD841B8A613}")) || ver < 0x0234) // dvobsub auto
- && clsid != CLSID_madVR
- && clsid != CLSID_DXR) { // Haali's video renderer
- return E_FAIL;
- }
- }
- }
-
- return __super::CheckConnect(dir, pPin);
-}
-
-int NextMpegStartCode(CGolombBuffer& gb, BYTE& code, __int64 len)
-{
- gb.BitByteAlign();
- DWORD dw = (DWORD) - 1;
- do {
- if (len-- == 0) {
- return false;
- }
- dw = (dw << 8) | (BYTE)gb.BitRead(8);
- } while ((dw & 0xffffff00) != 0x00000100);
- code = (BYTE)(dw & 0xff);
- return true;
-}
-
-HRESULT CMpeg2DecFilter::CheckInputType(const CMediaType* mtIn)
-{
- if (mtIn->formattype == FORMAT_MPEG2_VIDEO && mtIn->pbFormat) {
- MPEG2VIDEOINFO* vih = (MPEG2VIDEOINFO*)mtIn->pbFormat;
- if (vih->cbSequenceHeader > 0 && (vih->dwSequenceHeader[0] & 0x00ffffff) != 0x00010000) {
- return VFW_E_TYPE_NOT_ACCEPTED;
- }
- BYTE* pSequenceHeader = (BYTE*)vih->dwSequenceHeader;
- DWORD cbSequenceHeader = vih->cbSequenceHeader;
-
- BYTE id = 0;
- CGolombBuffer gb(pSequenceHeader, cbSequenceHeader);
- while (gb.GetPos() < gb.GetSize() && id != 0xb5) {
- if (!NextMpegStartCode(gb, id, cbSequenceHeader)) {
- break;
- }
- }
- if (id == 0xb5) {
- gb.BitRead(4); // startcodeid
- gb.BitRead(1); // profile_levelescape
- gb.BitRead(3); // profile
- gb.BitRead(4); // level
- gb.BitRead(1); // interlaced
- BYTE chroma = (BYTE)gb.BitRead(2);
- if (chroma >= 2) { // current support only 4:2:0 profile
- return VFW_E_TYPE_NOT_ACCEPTED;
- }
- }
- }
-
- return (mtIn->majortype == MEDIATYPE_DVD_ENCRYPTED_PACK && mtIn->subtype == MEDIASUBTYPE_MPEG2_VIDEO
- || mtIn->majortype == MEDIATYPE_MPEG2_PACK && mtIn->subtype == MEDIASUBTYPE_MPEG2_VIDEO
- || mtIn->majortype == MEDIATYPE_MPEG2_PES && mtIn->subtype == MEDIASUBTYPE_MPEG2_VIDEO
- || mtIn->majortype == MEDIATYPE_Video && mtIn->subtype == MEDIASUBTYPE_MPEG2_VIDEO
- || mtIn->majortype == MEDIATYPE_Video && mtIn->subtype == MEDIASUBTYPE_MPG2
- || mtIn->majortype == MEDIATYPE_Video && mtIn->subtype == MEDIASUBTYPE_MPEG1Packet
- || mtIn->majortype == MEDIATYPE_Video && mtIn->subtype == MEDIASUBTYPE_MPEG1Payload)
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
-}
-
-HRESULT CMpeg2DecFilter::CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut)
-{
- bool fPlanarYUV = mtOut->subtype == MEDIASUBTYPE_YV12
- || mtOut->subtype == MEDIASUBTYPE_I420
- || mtOut->subtype == MEDIASUBTYPE_IYUV;
-
- return SUCCEEDED(__super::CheckTransform(mtIn, mtOut))
- && (!fPlanarYUV || IsPlanarYUVEnabled())
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
-}
-
-HRESULT CMpeg2DecFilter::SetMediaType(PIN_DIRECTION dir, const CMediaType* pmt)
-{
- HRESULT hr = __super::SetMediaType(dir, pmt);
-
- if (dir == PINDIR_INPUT) {
- // Compute the expected Pixel AR
- m_par.cx = m_arx * m_h;
- m_par.cy = m_ary * m_w;
- int gcd = GCD(m_par.cx, m_par.cy);
- if (gcd > 1) {
- m_par.cx /= gcd;
- m_par.cy /= gcd;
- }
- }
-
- return hr;
-}
-
-DWORD g_clock;
-
-HRESULT CMpeg2DecFilter::StartStreaming()
-{
- HRESULT hr = __super::StartStreaming();
- if (FAILED(hr)) {
- return hr;
- }
-
- m_dec.Attach(DEBUG_NEW CMpeg2Dec());
- if (!m_dec) {
- return E_OUTOFMEMORY;
- }
-
- InputTypeChanged();
-
- // g_clock = clock();
-
- return S_OK;
-}
-
-HRESULT CMpeg2DecFilter::StopStreaming()
-{
- /*
- CString str;
- str.Format(_T("%d"), clock()-g_clock);
- AfxMessageBox(str);
- */
- m_dec.Free();
-
- return __super::StopStreaming();
-}
-
-HRESULT CMpeg2DecFilter::AlterQuality(Quality q)
-{
- if (q.Late > 100 * 10000i64) {
- m_fDropFrames = true;
- } else if (q.Late <= 0) {
- m_fDropFrames = false;
- }
-
- //TRACE(_T("CMpeg2DecFilter::AlterQuality: Type=%d, Proportion=%d, Late=%I64d, TimeStamp=%I64d\n"), q.Type, q.Proportion, q.Late, q.TimeStamp);
- return S_OK;
-}
-
-// ISpecifyPropertyPages2
-
-STDMETHODIMP CMpeg2DecFilter::GetPages(CAUUID* pPages)
-{
- CheckPointer(pPages, E_POINTER);
-
- HRESULT hr = S_OK;
-
- pPages->cElems = 1;
- pPages->pElems = (GUID*)CoTaskMemAlloc(sizeof(GUID) * pPages->cElems);
- if (pPages->pElems != nullptr) {
- pPages->pElems[0] = __uuidof(CMpeg2DecSettingsWnd);
- } else {
- hr = E_OUTOFMEMORY;
- }
-
- return hr;
-}
-
-STDMETHODIMP CMpeg2DecFilter::CreatePage(const GUID& guid, IPropertyPage** ppPage)
-{
- CheckPointer(ppPage, E_POINTER);
-
- if (*ppPage != nullptr) {
- return E_INVALIDARG;
- }
-
- HRESULT hr;
-
- if (guid == __uuidof(CMpeg2DecSettingsWnd)) {
- (*ppPage = DEBUG_NEW CInternalPropertyPageTempl<CMpeg2DecSettingsWnd>(nullptr, &hr))->AddRef();
- }
-
- return *ppPage ? S_OK : E_FAIL;
-}
-
-// IMpeg2DecFilter
-
-STDMETHODIMP CMpeg2DecFilter::SetDeinterlaceMethod(ditype di)
-{
- CAutoLock cAutoLock(&m_csProps);
- m_ditype = di;
- return S_OK;
-}
-
-STDMETHODIMP_(ditype) CMpeg2DecFilter::GetDeinterlaceMethod()
-{
- CAutoLock cAutoLock(&m_csProps);
- return m_ditype;
-}
-
-void CMpeg2DecFilter::CalcBrCont(BYTE* YTbl, float bright, float cont)
-{
- int Cont = (int)(cont * 512);
- int Bright = (int)bright;
-
- for (int i = 0; i < 256; i++) {
- int y = ((Cont * (i - 16)) >> 9) + Bright + 16;
- YTbl[i] = min(max(y, 0), 255);
- //YTbl[i] = min(max(y, 16), 235);
- }
-}
-
-void CMpeg2DecFilter::CalcHueSat(BYTE* UTbl, BYTE* VTbl, float hue, float sat)
-{
- int Sat = (int)(sat * 512);
- double Hue = (hue * M_PI) / 180.0;
- int Sin = (int)(sin(Hue) * 4096);
- int Cos = (int)(cos(Hue) * 4096);
-
- for (int y = 0; y < 256; y++) {
- for (int x = 0; x < 256; x++) {
- int u = x - 128;
- int v = y - 128;
- int ux = (u * Cos + v * Sin) >> 12;
- v = (v * Cos - u * Sin) >> 12;
- u = ((ux * Sat) >> 9) + 128;
- v = ((v * Sat) >> 9) + 128;
- u = min(max(u, 16), 235);
- v = min(max(v, 16), 235);
- UTbl[(y << 8) | x] = u;
- VTbl[(y << 8) | x] = v;
- }
- }
-}
-
-void CMpeg2DecFilter::ApplyBrContHueSat(BYTE* srcy, BYTE* srcu, BYTE* srcv, int w, int h, int pitch)
-{
- CAutoLock cAutoLock(&m_csProps);
-
- if (fabs(m_bright) > EPSILON || fabs(m_cont - 1.0) > EPSILON) {
- int size = pitch * h;
-
- if ((g_cpuid.m_flags & CCpuID::sse2) && ((DWORD_PTR)srcy & 15) == 0) {
- short Cont = (short)(min(max(m_cont, 0) * 512, (1 << 16) - 1));
- short Bright = (short)(m_bright + 16);
-
- __m128i bc = _mm_set_epi16(Bright, Cont, Bright, Cont, Bright, Cont, Bright, Cont);
-
- __m128i zero = _mm_setzero_si128();
- __m128i _16 = _mm_set1_epi16(16);
- __m128i _512 = _mm_set1_epi16(512);
-
- for (int i = 0, j = size >> 4; i < j; i++) {
- __m128i r = _mm_load_si128((__m128i*)&srcy[i * 16]);
-
- __m128i rl = _mm_unpacklo_epi8(r, zero);
- __m128i rh = _mm_unpackhi_epi8(r, zero);
-
- rl = _mm_subs_epi16(rl, _16);
- rh = _mm_subs_epi16(rh, _16);
-
- __m128i rll = _mm_unpacklo_epi16(rl, _512);
- __m128i rlh = _mm_unpackhi_epi16(rl, _512);
- __m128i rhl = _mm_unpacklo_epi16(rh, _512);
- __m128i rhh = _mm_unpackhi_epi16(rh, _512);
-
- rll = _mm_madd_epi16(rll, bc);
- rlh = _mm_madd_epi16(rlh, bc);
- rhl = _mm_madd_epi16(rhl, bc);
- rhh = _mm_madd_epi16(rhh, bc);
-
- rll = _mm_srai_epi32(rll, 9);
- rlh = _mm_srai_epi32(rlh, 9);
- rhl = _mm_srai_epi32(rhl, 9);
- rhh = _mm_srai_epi32(rhh, 9);
-
- rl = _mm_packs_epi32(rll, rlh);
- rh = _mm_packs_epi32(rhl, rhh);
-
- r = _mm_packus_epi16(rl, rh);
-
- _mm_store_si128((__m128i*)&srcy[i * 16], r);
- }
-
- srcy += size >> 4;
- size &= 15;
- }
-
- for (; size > 0; size--) {
- *srcy++ = m_YTbl[*srcy];
- }
- }
-
- pitch /= 2;
- w /= 2;
- h /= 2;
-
- if (fabs(m_hue) > EPSILON || fabs(m_sat - 1.0) > EPSILON) {
- for (int size = pitch * h; size > 0; size--) {
- WORD uv = (*srcv << 8) | *srcu;
- *srcu++ = m_UTbl[uv];
- *srcv++ = m_VTbl[uv];
- }
- }
-}
-
-STDMETHODIMP CMpeg2DecFilter::SetBrightness(float bright)
-{
- CAutoLock cAutoLock(&m_csProps);
- CalcBrCont(m_YTbl, m_bright = bright, m_cont);
- return S_OK;
-}
-
-STDMETHODIMP CMpeg2DecFilter::SetContrast(float cont)
-{
- CAutoLock cAutoLock(&m_csProps);
- CalcBrCont(m_YTbl, m_bright, m_cont = cont);
- return S_OK;
-}
-
-STDMETHODIMP CMpeg2DecFilter::SetHue(float hue)
-{
- CAutoLock cAutoLock(&m_csProps);
- CalcHueSat(m_UTbl, m_VTbl, m_hue = hue, m_sat);
- return S_OK;
-}
-
-STDMETHODIMP CMpeg2DecFilter::SetSaturation(float sat)
-{
- CAutoLock cAutoLock(&m_csProps);
- CalcHueSat(m_UTbl, m_VTbl, m_hue, m_sat = sat);
- return S_OK;
-}
-
-STDMETHODIMP_(float) CMpeg2DecFilter::GetBrightness()
-{
- CAutoLock cAutoLock(&m_csProps);
- return m_bright;
-}
-
-STDMETHODIMP_(float) CMpeg2DecFilter::GetContrast()
-{
- CAutoLock cAutoLock(&m_csProps);
- return m_cont;
-}
-
-STDMETHODIMP_(float) CMpeg2DecFilter::GetHue()
-{
- CAutoLock cAutoLock(&m_csProps);
- return m_hue;
-}
-
-STDMETHODIMP_(float) CMpeg2DecFilter::GetSaturation()
-{
- CAutoLock cAutoLock(&m_csProps);
- return m_sat;
-}
-
-STDMETHODIMP CMpeg2DecFilter::EnableForcedSubtitles(bool fEnable)
-{
- CAutoLock cAutoLock(&m_csProps);
- m_fForcedSubs = fEnable;
- return S_OK;
-}
-
-STDMETHODIMP_(bool) CMpeg2DecFilter::IsForcedSubtitlesEnabled()
-{
- CAutoLock cAutoLock(&m_csProps);
- return m_fForcedSubs;
-}
-
-STDMETHODIMP CMpeg2DecFilter::EnablePlanarYUV(bool fEnable)
-{
- CAutoLock cAutoLock(&m_csProps);
- m_fPlanarYUV = fEnable;
- return S_OK;
-}
-
-STDMETHODIMP_(bool) CMpeg2DecFilter::IsPlanarYUVEnabled()
-{
- CAutoLock cAutoLock(&m_csProps);
- return m_fPlanarYUV;
-}
-
-STDMETHODIMP CMpeg2DecFilter::EnableInterlaced(bool fEnable)
-{
- CAutoLock cAutoLock(&m_csProps);
- m_fInterlaced = fEnable;
- return S_OK;
-}
-
-STDMETHODIMP_(bool) CMpeg2DecFilter::IsInterlacedEnabled()
-{
- CAutoLock cAutoLock(&m_csProps);
- return m_fInterlaced;
-}
-
-STDMETHODIMP CMpeg2DecFilter::EnableReadARFromStream(bool fEnable)
-{
- CAutoLock cAutoLock(&m_csProps);
- m_bReadARFromStream = fEnable;
- return S_OK;
-}
-
-STDMETHODIMP_(bool) CMpeg2DecFilter::IsReadARFromStreamEnabled()
-{
- CAutoLock cAutoLock(&m_csProps);
- return m_bReadARFromStream;
-}
-
-//
-// CMpeg2DecInputPin
-//
-
-CMpeg2DecInputPin::CMpeg2DecInputPin(CTransformFilter* pFilter, HRESULT* phr, LPWSTR pName)
- : CDeCSSInputPin(NAME("CMpeg2DecInputPin"), pFilter, phr, pName)
-{
- m_CorrectTS = 0;
- m_ratechange.Rate = 10000;
- m_ratechange.StartTime = _I64_MAX;
-}
-
-// IKsPropertySet
-
-STDMETHODIMP CMpeg2DecInputPin::Set(REFGUID PropSet, ULONG Id, LPVOID pInstanceData, ULONG InstanceLength, LPVOID pPropertyData, ULONG DataLength)
-{
- if (PropSet != AM_KSPROPSETID_TSRateChange /*&& PropSet != AM_KSPROPSETID_DVD_RateChange*/) {
- return __super::Set(PropSet, Id, pInstanceData, InstanceLength, pPropertyData, DataLength);
- }
-
- if (PropSet == AM_KSPROPSETID_TSRateChange)
- switch (Id) {
- case AM_RATE_SimpleRateChange: {
- AM_SimpleRateChange* p = (AM_SimpleRateChange*)pPropertyData;
- if (!m_CorrectTS) {
- return E_PROP_ID_UNSUPPORTED;
- }
- CAutoLock cAutoLock(&m_csRateLock);
- m_ratechange = *p;
- DbgLog((LOG_TRACE, 0, _T("StartTime=%I64d, Rate=%d"), p->StartTime, p->Rate));
- }
- break;
- case AM_RATE_UseRateVersion: {
- WORD* p = (WORD*)pPropertyData;
- if (*p > 0x0101) {
- return E_PROP_ID_UNSUPPORTED;
- }
- }
- break;
- case AM_RATE_CorrectTS: {
- LONG* p = (LONG*)pPropertyData;
- m_CorrectTS = *p;
- }
- break;
- default:
- return E_PROP_ID_UNSUPPORTED;
- }
- /*
- if (PropSet == AM_KSPROPSETID_DVD_RateChange)
- switch (Id)
- {
- case AM_RATE_ChangeRate:
- {
- AM_DVD_ChangeRate* p = (AM_DVD_ChangeRate*)pPropertyData;
- }
- break;
- default:
- return E_PROP_ID_UNSUPPORTED;
- }
- */
- return S_OK;
-}
-
-STDMETHODIMP CMpeg2DecInputPin::Get(REFGUID PropSet, ULONG Id, LPVOID pInstanceData, ULONG InstanceLength, LPVOID pPropertyData, ULONG DataLength, ULONG* pBytesReturned)
-{
- if (PropSet != AM_KSPROPSETID_TSRateChange /*&& PropSet != AM_KSPROPSETID_DVD_RateChange*/) {
- return __super::Get(PropSet, Id, pInstanceData, InstanceLength, pPropertyData, DataLength, pBytesReturned);
- }
-
- if (PropSet == AM_KSPROPSETID_TSRateChange)
- switch (Id) {
- case AM_RATE_SimpleRateChange: {
- AM_SimpleRateChange* p = (AM_SimpleRateChange*)pPropertyData;
- UNREFERENCED_PARAMETER(p);
- return E_PROP_ID_UNSUPPORTED;
- }
- break;
- case AM_RATE_MaxFullDataRate: {
- AM_MaxFullDataRate* p = (AM_MaxFullDataRate*)pPropertyData;
- UNREFERENCED_PARAMETER(p);
- *p = 8 * 10000;
- *pBytesReturned = sizeof(AM_MaxFullDataRate);
- }
- break;
- case AM_RATE_QueryFullFrameRate: {
- AM_QueryRate* p = (AM_QueryRate*)pPropertyData;
- p->lMaxForwardFullFrame = 8 * 10000;
- p->lMaxReverseFullFrame = 8 * 10000;
- *pBytesReturned = sizeof(AM_QueryRate);
- }
- break;
- case AM_RATE_QueryLastRateSegPTS: {
- //REFERENCE_TIME* p = (REFERENCE_TIME*)pPropertyData;
- return E_PROP_ID_UNSUPPORTED;
- }
- break;
- default:
- return E_PROP_ID_UNSUPPORTED;
- }
- /*
- if (PropSet == AM_KSPROPSETID_DVD_RateChange)
- switch (Id)
- {
- case AM_RATE_FullDataRateMax:
- {
- AM_MaxFullDataRate* p = (AM_MaxFullDataRate*)pPropertyData;
- }
- break;
- case AM_RATE_ReverseDecode:
- {
- LONG* p = (LONG*)pPropertyData;
- }
- break;
- case AM_RATE_DecoderPosition:
- {
- AM_DVD_DecoderPosition* p = (AM_DVD_DecoderPosition*)pPropertyData;
- }
- break;
- case AM_RATE_DecoderVersion:
- {
- LONG* p = (LONG*)pPropertyData;
- }
- break;
- default:
- return E_PROP_ID_UNSUPPORTED;
- }
- */
- return S_OK;
-}
-
-STDMETHODIMP CMpeg2DecInputPin::QuerySupported(REFGUID PropSet, ULONG Id, ULONG* pTypeSupport)
-{
- if (PropSet != AM_KSPROPSETID_TSRateChange /*&& PropSet != AM_KSPROPSETID_DVD_RateChange*/) {
- return __super::QuerySupported(PropSet, Id, pTypeSupport);
- }
-
- if (PropSet == AM_KSPROPSETID_TSRateChange)
- switch (Id) {
- case AM_RATE_SimpleRateChange:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET | KSPROPERTY_SUPPORT_SET;
- break;
- case AM_RATE_MaxFullDataRate:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET;
- break;
- case AM_RATE_UseRateVersion:
- *pTypeSupport = KSPROPERTY_SUPPORT_SET;
- break;
- case AM_RATE_QueryFullFrameRate:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET;
- break;
- case AM_RATE_QueryLastRateSegPTS:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET;
- break;
- case AM_RATE_CorrectTS:
- *pTypeSupport = KSPROPERTY_SUPPORT_SET;
- break;
- default:
- return E_PROP_ID_UNSUPPORTED;
- }
- /*
- if (PropSet == AM_KSPROPSETID_DVD_RateChange)
- switch (Id)
- {
- case AM_RATE_ChangeRate:
- *pTypeSupport = KSPROPERTY_SUPPORT_SET;
- break;
- case AM_RATE_FullDataRateMax:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET;
- break;
- case AM_RATE_ReverseDecode:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET;
- break;
- case AM_RATE_DecoderPosition:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET;
- break;
- case AM_RATE_DecoderVersion:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET;
- break;
- default:
- return E_PROP_ID_UNSUPPORTED;
- }
- */
- return S_OK;
-}
-
-//
-// CMpeg2DecOutputPin
-//
-
-CMpeg2DecOutputPin::CMpeg2DecOutputPin(CBaseVideoFilter* pFilter, HRESULT* phr, LPWSTR pName)
- : CBaseVideoOutputPin(NAME("CMpeg2DecOutputPin"), pFilter, phr, pName)
-{
-}
-
-HRESULT CMpeg2DecOutputPin::Active()
-{
- CAutoLock cAutoLock(m_pLock);
-
- // TODO
-
- if (m_Connected && !m_pOutputQueue) {
- HRESULT hr = NOERROR;
-
- m_pOutputQueue.Attach(DEBUG_NEW COutputQueue(m_Connected, &hr));
- if (!m_pOutputQueue) {
- hr = E_OUTOFMEMORY;
- }
-
- if (FAILED(hr)) {
- m_pOutputQueue.Free();
- return hr;
- }
- }
-
- return __super::Active();
-}
-
-HRESULT CMpeg2DecOutputPin::Inactive()
-{
- CAutoLock cAutoLock(m_pLock);
- m_pOutputQueue.Free();
- return __super::Inactive();
-}
-
-HRESULT CMpeg2DecOutputPin::Deliver(IMediaSample* pMediaSample)
-{
- if (!m_pOutputQueue) {
- return NOERROR;
- }
- pMediaSample->AddRef();
- return m_pOutputQueue->Receive(pMediaSample);
-}
-
-HRESULT CMpeg2DecOutputPin::DeliverEndOfStream()
-{
- CallQueue(EOS());
-}
-
-HRESULT CMpeg2DecOutputPin::DeliverBeginFlush()
-{
- CallQueue(BeginFlush());
-}
-
-HRESULT CMpeg2DecOutputPin::DeliverEndFlush()
-{
- CallQueue(EndFlush());
-}
-
-HRESULT CMpeg2DecOutputPin::DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
-{
- CallQueue(NewSegment(tStart, tStop, dRate));
-}
-
-
-//
-// CSubpicInputPin
-//
-
-#define PTS2RT(pts) (10000i64 * pts / 90)
-
-CSubpicInputPin::CSubpicInputPin(CTransformFilter* pFilter, HRESULT* phr)
- : CMpeg2DecInputPin(pFilter, phr, L"SubPicture")
- , m_spon(TRUE)
- , m_fsppal(false)
-{
- m_sppal[0].Y = 0x00;
- m_sppal[0].U = m_sppal[0].V = 0x80;
- m_sppal[1].Y = 0xe0;
- m_sppal[1].U = m_sppal[1].V = 0x80;
- m_sppal[2].Y = 0x80;
- m_sppal[2].U = m_sppal[2].V = 0x80;
- m_sppal[3].Y = 0x20;
- m_sppal[3].U = m_sppal[3].V = 0x80;
-}
-
-HRESULT CSubpicInputPin::CheckMediaType(const CMediaType* mtIn)
-{
- return (mtIn->majortype == MEDIATYPE_DVD_ENCRYPTED_PACK
- || mtIn->majortype == MEDIATYPE_MPEG2_PACK
- || mtIn->majortype == MEDIATYPE_MPEG2_PES
- || mtIn->majortype == MEDIATYPE_Video)
- && (mtIn->subtype == MEDIASUBTYPE_DVD_SUBPICTURE
- || mtIn->subtype == MEDIASUBTYPE_CVD_SUBPICTURE
- || mtIn->subtype == MEDIASUBTYPE_SVCD_SUBPICTURE)
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
-}
-
-HRESULT CSubpicInputPin::SetMediaType(const CMediaType* mtIn)
-{
- return CBasePin::SetMediaType(mtIn);
-}
-
-bool CSubpicInputPin::HasAnythingToRender(REFERENCE_TIME rt)
-{
- if (!IsConnected()) {
- return false;
- }
-
- CAutoLock cAutoLock(&m_csReceive);
-
- POSITION pos = m_sps.GetHeadPosition();
- while (pos) {
- spu* sp = m_sps.GetNext(pos);
- if (sp->m_rtStart <= rt && rt < sp->m_rtStop && (/*sp->m_psphli ||*/ sp->m_fForced || m_spon)) {
- return true;
- }
- }
-
- return false;
-}
-
-void CSubpicInputPin::RenderSubpics(REFERENCE_TIME rt, BYTE** yuv, int w, int h)
-{
- CAutoLock cAutoLock(&m_csReceive);
-
- POSITION pos;
-
- // remove no longer needed things first
- pos = m_sps.GetHeadPosition();
- while (pos) {
- POSITION cur = pos;
- spu* sp = m_sps.GetNext(pos);
- if (sp->m_rtStop <= rt) {
- m_sps.RemoveAt(cur);
- }
- }
-
- pos = m_sps.GetHeadPosition();
- while (pos) {
- spu* sp = m_sps.GetNext(pos);
- if (sp->m_rtStart <= rt && rt < sp->m_rtStop
- && (m_spon || sp->m_fForced && ((static_cast<CMpeg2DecFilter*>(m_pFilter))->IsForcedSubtitlesEnabled() || sp->m_psphli))) {
- sp->Render(rt, yuv, w, h, m_sppal, m_fsppal);
- }
- }
-}
-
-HRESULT CSubpicInputPin::Transform(IMediaSample* pSample)
-{
- HRESULT hr;
-
- AM_MEDIA_TYPE* pmt;
- if (SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt) {
- CMediaType mt(*pmt);
- SetMediaType(&mt);
- DeleteMediaType(pmt);
- }
-
- BYTE* pDataIn = nullptr;
- if (FAILED(hr = pSample->GetPointer(&pDataIn))) {
- return hr;
- }
-
- long len = pSample->GetActualDataLength();
-
- StripPacket(pDataIn, len);
-
- if (len <= 0) {
- return S_FALSE;
- }
-
- if (m_mt.subtype == MEDIASUBTYPE_SVCD_SUBPICTURE) {
- pDataIn += 4;
- len -= 4;
- }
-
- if (len <= 0) {
- return S_FALSE;
- }
-
- CAutoLock cAutoLock(&m_csReceive);
-
- REFERENCE_TIME rtStart = 0, rtStop = 0;
- hr = pSample->GetTime(&rtStart, &rtStop);
-
- bool fRefresh = false;
-
- if (FAILED(hr)) {
- if (!m_sps.IsEmpty()) {
- spu* sp = m_sps.GetTail();
- sp->SetCount(sp->GetCount() + len);
- memcpy(sp->GetData() + sp->GetCount() - len, pDataIn, len);
- }
- } else {
- POSITION pos = m_sps.GetTailPosition();
- while (pos) {
- spu* sp = m_sps.GetPrev(pos);
- if (sp->m_rtStop == _I64_MAX) {
- sp->m_rtStop = rtStart;
- break;
- }
- }
-
- CAutoPtr<spu> p;
-
- if (m_mt.subtype == MEDIASUBTYPE_DVD_SUBPICTURE) {
- p.Attach(DEBUG_NEW dvdspu());
- } else if (m_mt.subtype == MEDIASUBTYPE_CVD_SUBPICTURE) {
- p.Attach(DEBUG_NEW cvdspu());
- } else if (m_mt.subtype == MEDIASUBTYPE_SVCD_SUBPICTURE) {
- p.Attach(DEBUG_NEW svcdspu());
- } else {
- return E_FAIL;
- }
-
- p->m_rtStart = rtStart;
- p->m_rtStop = _I64_MAX;
-
- p->SetCount(len);
- memcpy(p->GetData(), pDataIn, len);
-
- if (m_sphli && p->m_rtStart == PTS2RT(m_sphli->StartPTM)) {
- p->m_psphli = m_sphli;
- fRefresh = true;
- }
-
- m_sps.AddTail(p);
- }
-
- if (!m_sps.IsEmpty()) {
- m_sps.GetTail()->Parse();
- }
-
- if (fRefresh) {
- //((CMpeg2DecFilter*)m_pFilter)->Deliver(true);
- }
-
- return S_FALSE;
-}
-
-STDMETHODIMP CSubpicInputPin::EndFlush()
-{
- CAutoLock cAutoLock(&m_csReceive);
- m_sps.RemoveAll();
- return S_OK;
-}
-
-// IKsPropertySet
-
-STDMETHODIMP CSubpicInputPin::Set(REFGUID PropSet, ULONG Id, LPVOID pInstanceData, ULONG InstanceLength, LPVOID pPropertyData, ULONG DataLength)
-{
- if (PropSet != AM_KSPROPSETID_DvdSubPic) {
- return __super::Set(PropSet, Id, pInstanceData, InstanceLength, pPropertyData, DataLength);
- }
-
- bool fRefresh = false;
-
- switch (Id) {
- case AM_PROPERTY_DVDSUBPIC_PALETTE: {
- CAutoLock cAutoLock(&m_csReceive);
-
- AM_PROPERTY_SPPAL* pSPPAL = (AM_PROPERTY_SPPAL*)pPropertyData;
- memcpy(m_sppal, pSPPAL->sppal, sizeof(AM_PROPERTY_SPPAL));
- m_fsppal = true;
-
- DbgLog((LOG_TRACE, 0, _T("new palette")));
- }
- break;
- case AM_PROPERTY_DVDSUBPIC_HLI: {
- CAutoLock cAutoLock(&m_csReceive);
-
- AM_PROPERTY_SPHLI* pSPHLI = (AM_PROPERTY_SPHLI*)pPropertyData;
-
- m_sphli.Free();
-
- if (pSPHLI->HLISS) {
- POSITION pos = m_sps.GetHeadPosition();
- while (pos) {
- spu* sp = m_sps.GetNext(pos);
- if (sp->m_rtStart <= PTS2RT(pSPHLI->StartPTM) && PTS2RT(pSPHLI->StartPTM) < sp->m_rtStop) {
- fRefresh = true;
- sp->m_psphli.Free();
- sp->m_psphli.Attach(DEBUG_NEW AM_PROPERTY_SPHLI);
- memcpy((AM_PROPERTY_SPHLI*)sp->m_psphli, pSPHLI, sizeof(AM_PROPERTY_SPHLI));
- }
- }
-
- if (!fRefresh) { // save it for later, a subpic might be late for this hli
- m_sphli.Attach(DEBUG_NEW AM_PROPERTY_SPHLI);
- memcpy((AM_PROPERTY_SPHLI*)m_sphli, pSPHLI, sizeof(AM_PROPERTY_SPHLI));
- }
- } else {
- POSITION pos = m_sps.GetHeadPosition();
- while (pos) {
- spu* sp = m_sps.GetNext(pos);
- fRefresh |= !!sp->m_psphli;
- sp->m_psphli.Free();
- }
- }
-
- if (pSPHLI->HLISS)
- DbgLog((LOG_TRACE, 0, _T("hli: %I64d - %I64d, (%d,%d) - (%d,%d)"),
- PTS2RT(pSPHLI->StartPTM) / 10000, PTS2RT(pSPHLI->EndPTM) / 10000,
- pSPHLI->StartX, pSPHLI->StartY, pSPHLI->StopX, pSPHLI->StopY));
- }
- break;
- case AM_PROPERTY_DVDSUBPIC_COMPOSIT_ON: {
- CAutoLock cAutoLock(&m_csReceive);
-
- AM_PROPERTY_COMPOSIT_ON* pCompositOn = (AM_PROPERTY_COMPOSIT_ON*)pPropertyData;
- m_spon = *pCompositOn;
- }
- break;
- default:
- return E_PROP_ID_UNSUPPORTED;
- }
-
- if (fRefresh) {
- (static_cast<CMpeg2DecFilter*>(m_pFilter))->Deliver(true);
- }
-
- return S_OK;
-}
-
-STDMETHODIMP CSubpicInputPin::QuerySupported(REFGUID PropSet, ULONG Id, ULONG* pTypeSupport)
-{
- if (PropSet != AM_KSPROPSETID_DvdSubPic) {
- return __super::QuerySupported(PropSet, Id, pTypeSupport);
- }
-
- switch (Id) {
- case AM_PROPERTY_DVDSUBPIC_PALETTE:
- *pTypeSupport = KSPROPERTY_SUPPORT_SET;
- break;
- case AM_PROPERTY_DVDSUBPIC_HLI:
- *pTypeSupport = KSPROPERTY_SUPPORT_SET;
- break;
- case AM_PROPERTY_DVDSUBPIC_COMPOSIT_ON:
- *pTypeSupport = KSPROPERTY_SUPPORT_SET;
- break;
- default:
- return E_PROP_ID_UNSUPPORTED;
- }
-
- return S_OK;
-}
-
-// CSubpicInputPin::spu
-
-static __inline BYTE GetNibble(BYTE* p, DWORD* offset, int& nField, int& fAligned)
-{
- BYTE ret = (p[offset[nField]] >> (fAligned << 2)) & 0x0f;
- offset[nField] += 1 - fAligned;
- fAligned = !fAligned;
- return ret;
-}
-
-static __inline BYTE GetHalfNibble(BYTE* p, DWORD* offset, int& nField, int& n)
-{
- BYTE ret = (p[offset[nField]] >> (n << 1)) & 0x03;
- if (!n) {
- offset[nField]++;
- }
- n = (n - 1 + 4) & 3;
- return ret;
-}
-
-static __inline void DrawPixel(BYTE** yuv, CPoint pt, int pitch, AM_DVD_YUV& c)
-{
- if (c.Reserved == 0) {
- return;
- }
-
- BYTE* p = &yuv[0][pt.y * pitch + pt.x];
- //*p = (*p*(15-contrast) + sppal[color].Y*contrast)>>4;
- *p -= (*p - c.Y) * c.Reserved >> 4;
-
- if (pt.y & 1) {
- return; // since U/V is half res there is no need to overwrite the same line again
- }
-
- pt.x = (pt.x + 1) / 2;
- pt.y = (pt.y /*+ 1*/) / 2; // only paint the upper field always, don't round it
- pitch /= 2;
-
- // U/V is exchanged? wierd but looks true when comparing the outputted colors from other decoders
-
- p = &yuv[1][pt.y * pitch + pt.x];
- //*p = (BYTE)(((((int)*p-0x80)*(15-contrast) + ((int)sppal[color].V-0x80)*contrast) >> 4) + 0x80);
- *p -= (*p - c.V) * c.Reserved >> 4;
-
- p = &yuv[2][pt.y * pitch + pt.x];
- //*p = (BYTE)(((((int)*p-0x80)*(15-contrast) + ((int)sppal[color].U-0x80)*contrast) >> 4) + 0x80);
- *p -= (*p - c.U) * c.Reserved >> 4;
-
- // Neighter of the blending formulas are accurate (">>4" should be "/15").
- // Even though the second one is a bit worse, since we are scaling the difference only,
- // the error is still not noticable.
-}
-
-static __inline void DrawPixels(BYTE** yuv, int pitch, CPoint pt, int len, AM_DVD_YUV& c, CRect& rc)
-{
- if (pt.y < rc.top || pt.y >= rc.bottom) {
- return;
- }
- if (pt.x < rc.left) {
- len -= rc.left - pt.x;
- pt.x = rc.left;
- }
- if (pt.x + len > rc.right) {
- len = rc.right - pt.x;
- }
- if (len <= 0 || pt.x >= rc.right) {
- return;
- }
-
- if (c.Reserved == 0) {
- if (rc.IsRectEmpty()) {
- return;
- }
-
- if (pt.y < rc.top || pt.y >= rc.bottom
- || pt.x + len < rc.left || pt.x >= rc.right) {
- return;
- }
- }
-
- while (len-- > 0) {
- DrawPixel(yuv, pt, pitch, c);
- pt.x++;
- }
-}
-
-// CSubpicInputPin::dvdspu
-
-bool CSubpicInputPin::dvdspu::Parse()
-{
- m_offsets.RemoveAll();
-
- BYTE* p = GetData();
-
- WORD packetsize = (p[0] << 8) | p[1];
- WORD datasize = (p[2] << 8) | p[3];
-
- if (packetsize > GetCount() || datasize > packetsize) {
- return false;
- }
-
- int i, next = datasize;
-
-#define GetWORD (p[i] << 8) | p[i+1]; i += 2
-
- do {
- i = next;
-
- int pts = GetWORD;
- next = GetWORD;
-
- if (next > packetsize || next < datasize) {
- return false;
- }
-
- REFERENCE_TIME rt = m_rtStart + 1024 * PTS2RT(pts);
-
- for (bool fBreak = false; !fBreak;) {
- int len = 0;
-
- switch (p[i]) {
- case 0x00:
- len = 0;
- break;
- case 0x01:
- len = 0;
- break;
- case 0x02:
- len = 0;
- break;
- case 0x03:
- len = 2;
- break;
- case 0x04:
- len = 2;
- break;
- case 0x05:
- len = 6;
- break;
- case 0x06:
- len = 4;
- break;
- case 0x07:
- len = 0;
- break; // TODO
- default:
- len = 0;
- break;
- }
-
- if (i + len >= packetsize) {
- TRACE(_T("Warning: Wrong subpicture parameter block ending\n"));
- break;
- }
-
- switch (p[i++]) {
- case 0x00: // forced start displaying
- m_fForced = true;
- break;
- case 0x01: // normal start displaying
- m_fForced = false;
- break;
- case 0x02: // stop displaying
- m_rtStop = rt;
- break;
- case 0x03:
- m_sphli.ColCon.emph2col = p[i] >> 4;
- m_sphli.ColCon.emph1col = p[i] & 0xf;
- m_sphli.ColCon.patcol = p[i + 1] >> 4;
- m_sphli.ColCon.backcol = p[i + 1] & 0xf;
- i += 2;
- break;
- case 0x04:
- m_sphli.ColCon.emph2con = p[i] >> 4;
- m_sphli.ColCon.emph1con = p[i] & 0xf;
- m_sphli.ColCon.patcon = p[i + 1] >> 4;
- m_sphli.ColCon.backcon = p[i + 1] & 0xf;
- i += 2;
- break;
- case 0x05:
- m_sphli.StartX = (p[i] << 4) + (p[i + 1] >> 4);
- m_sphli.StopX = ((p[i + 1] & 0x0f) << 8) + p[i + 2] + 1;
- m_sphli.StartY = (p[i + 3] << 4) + (p[i + 4] >> 4);
- m_sphli.StopY = ((p[i + 4] & 0x0f) << 8) + p[i + 5] + 1;
- i += 6;
- break;
- case 0x06:
- m_offset[0] = GetWORD;
- m_offset[1] = GetWORD;
- break;
- case 0x07:
- // TODO
- break;
- case 0xff: // end of ctrlblk
- fBreak = true;
- continue;
- default: // skip this ctrlblk
- fBreak = true;
- break;
- }
- }
-
- offset_t o = {rt, m_sphli};
- m_offsets.AddTail(o); // is it always going to be sorted?
- } while (i <= next && i < packetsize);
-
- return true;
-}
-
-void CSubpicInputPin::dvdspu::Render(REFERENCE_TIME rt, BYTE** yuv, int w, int h, AM_DVD_YUV* sppal, bool fsppal)
-{
- BYTE* p = GetData();
- DWORD offset[2] = {m_offset[0], m_offset[1]};
-
- AM_PROPERTY_SPHLI sphli = m_sphli;
- CPoint pt(sphli.StartX, sphli.StartY);
- CRect rc(pt, CPoint(sphli.StopX, sphli.StopY));
-
- CRect rcclip(0, 0, w, h);
- rcclip &= rc;
-
- if (m_psphli) {
- rcclip &= CRect(m_psphli->StartX, m_psphli->StartY, m_psphli->StopX, m_psphli->StopY);
- sphli = *m_psphli;
- } else if (m_offsets.GetCount() > 1) {
- POSITION pos = m_offsets.GetTailPosition();
- while (pos) {
- const offset_t& o = m_offsets.GetPrev(pos);
- if (rt >= o.rt) {
- sphli = o.sphli;
- break;
- }
- }
- }
-
- AM_DVD_YUV pal[4];
- pal[0] = sppal[fsppal ? sphli.ColCon.backcol : 0];
- pal[0].Reserved = sphli.ColCon.backcon;
- pal[1] = sppal[fsppal ? sphli.ColCon.patcol : 1];
- pal[1].Reserved = sphli.ColCon.patcon;
- pal[2] = sppal[fsppal ? sphli.ColCon.emph1col : 2];
- pal[2].Reserved = sphli.ColCon.emph1con;
- pal[3] = sppal[fsppal ? sphli.ColCon.emph2col : 3];
- pal[3].Reserved = sphli.ColCon.emph2con;
-
- int nField = 0;
- int fAligned = 1;
-
- DWORD end[2] = {offset[1], (p[2] << 8) | p[3]};
-
- while ((nField == 0 && offset[0] < end[0]) || (nField == 1 && offset[1] < end[1])) {
- DWORD code;
-
- if ((code = GetNibble(p, offset, nField, fAligned)) >= 0x4
- || (code = (code << 4) | GetNibble(p, offset, nField, fAligned)) >= 0x10
- || (code = (code << 4) | GetNibble(p, offset, nField, fAligned)) >= 0x40
- || (code = (code << 4) | GetNibble(p, offset, nField, fAligned)) >= 0x100) {
- DrawPixels(yuv, w, pt, code >> 2, pal[code & 3], rcclip);
- if ((pt.x += code >> 2) < rc.right) {
- continue;
- }
- }
-
- DrawPixels(yuv, w, pt, rc.right - pt.x, pal[code & 3], rcclip);
-
- if (!fAligned) {
- GetNibble(p, offset, nField, fAligned); // align to byte
- }
-
- pt.x = rc.left;
- pt.y++;
- nField = 1 - nField;
- }
-}
-
-// CSubpicInputPin::cvdspu
-
-bool CSubpicInputPin::cvdspu::Parse()
-{
- BYTE* p = GetData();
-
- WORD packetsize = (p[0] << 8) | p[1];
- WORD datasize = (p[2] << 8) | p[3];
-
- if (packetsize > GetCount() || datasize > packetsize) {
- return false;
- }
-
- p = GetData() + datasize;
-
- for (int i = datasize, j = packetsize - 4; i <= j; i += 4, p += 4) {
- switch (p[0]) {
- case 0x0c:
- break;
- case 0x04:
- m_rtStop = m_rtStart + 10000i64 * ((p[1] << 16) | (p[2] << 8) | p[3]) / 90;
- break;
- case 0x17:
- m_sphli.StartX = ((p[1] & 0x0f) << 6) + (p[2] >> 2);
- m_sphli.StartY = ((p[2] & 0x03) << 8) + p[3];
- break;
- case 0x1f:
- m_sphli.StopX = ((p[1] & 0x0f) << 6) + (p[2] >> 2);
- m_sphli.StopY = ((p[2] & 0x03) << 8) + p[3];
- break;
- case 0x24:
- case 0x25:
- case 0x26:
- case 0x27:
- m_sppal[0][p[0] - 0x24].Y = p[1];
- m_sppal[0][p[0] - 0x24].U = p[2];
- m_sppal[0][p[0] - 0x24].V = p[3];
- break;
- case 0x2c:
- case 0x2d:
- case 0x2e:
- case 0x2f:
- m_sppal[1][p[0] - 0x2c].Y = p[1];
- m_sppal[1][p[0] - 0x2c].U = p[2];
- m_sppal[1][p[0] - 0x2c].V = p[3];
- break;
- case 0x37:
- m_sppal[0][3].Reserved = p[2] >> 4;
- m_sppal[0][2].Reserved = p[2] & 0xf;
- m_sppal[0][1].Reserved = p[3] >> 4;
- m_sppal[0][0].Reserved = p[3] & 0xf;
- break;
- case 0x3f:
- m_sppal[1][3].Reserved = p[2] >> 4;
- m_sppal[1][2].Reserved = p[2] & 0xf;
- m_sppal[1][1].Reserved = p[3] >> 4;
- m_sppal[1][0].Reserved = p[3] & 0xf;
- break;
- case 0x47:
- m_offset[0] = (p[2] << 8) | p[3];
- break;
- case 0x4f:
- m_offset[1] = (p[2] << 8) | p[3];
- break;
- default:
- break;
- }
- }
-
- return true;
-}
-
-void CSubpicInputPin::cvdspu::Render(REFERENCE_TIME rt, BYTE** yuv, int w, int h, AM_DVD_YUV* sppal, bool fsppal)
-{
- BYTE* p = GetData();
- DWORD offset[2] = {m_offset[0], m_offset[1]};
-
- CRect rcclip(0, 0, w, h);
-
- /* FIXME: startx/y looks to be wrong in the sample I tested
- CPoint pt(m_sphli.StartX, m_sphli.StartY);
- CRect rc(pt, CPoint(m_sphli.StopX, m_sphli.StopY));
- */
-
- CSize size(m_sphli.StopX - m_sphli.StartX, m_sphli.StopY - m_sphli.StartY);
- CPoint pt((rcclip.Width() - size.cx) / 2, (rcclip.Height() * 3 - size.cy * 1) / 4);
- CRect rc(pt, size);
-
- int nField = 0;
- int fAligned = 1;
-
- DWORD end[2] = {offset[1], (p[2] << 8) | p[3]};
-
- while ((nField == 0 && offset[0] < end[0]) || (nField == 1 && offset[1] < end[1])) {
- BYTE code;
-
- if ((code = GetNibble(p, offset, nField, fAligned)) >= 0x4) {
- DrawPixels(yuv, w, pt, code >> 2, m_sppal[0][code & 3], rcclip);
- pt.x += code >> 2;
- continue;
- }
-
- code = GetNibble(p, offset, nField, fAligned);
- DrawPixels(yuv, w, pt, rc.right - pt.x, m_sppal[0][code & 3], rcclip);
-
- if (!fAligned) {
- GetNibble(p, offset, nField, fAligned); // align to byte
- }
-
- pt.x = rc.left;
- pt.y++;
- nField = 1 - nField;
- }
-}
-
-// CSubpicInputPin::svcdspu
-
-bool CSubpicInputPin::svcdspu::Parse()
-{
- BYTE* p = GetData();
- BYTE* p0 = p;
-
- if (GetCount() < 2) {
- return false;
- }
-
- WORD packetsize = (p[0] << 8) | p[1];
- p += 2;
-
- if (packetsize > GetCount()) {
- return false;
- }
-
- bool duration = !!(*p++ & 0x04);
-
- p++; // unknown
-
- if (duration) {
- m_rtStop = m_rtStart + 10000i64 * ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]) / 90;
- p += 4;
- }
-
- m_sphli.StartX = m_sphli.StopX = (p[0] << 8) | p[1];
- p += 2;
- m_sphli.StartY = m_sphli.StopY = (p[0] << 8) | p[1];
- p += 2;
- m_sphli.StopX += (p[0] << 8) | p[1];
- p += 2;
- m_sphli.StopY += (p[0] << 8) | p[1];
- p += 2;
-
- for (int i = 0; i < 4; i++) {
- m_sppal[i].Y = *p++;
- m_sppal[i].U = *p++;
- m_sppal[i].V = *p++;
- m_sppal[i].Reserved = *p++ >> 4;
- }
-
- if (*p++ & 0xc0) {
- p += 4; // duration of the shift operation should be here, but it is untested
- }
-
- m_offset[1] = (p[0] << 8) | p[1];
- p += 2;
-
- m_offset[0] = p - p0;
- m_offset[1] += m_offset[0];
-
- return true;
-}
-
-void CSubpicInputPin::svcdspu::Render(REFERENCE_TIME rt, BYTE** yuv, int w, int h, AM_DVD_YUV* sppal, bool fsppal)
-{
- BYTE* p = GetData();
- DWORD offset[2] = {m_offset[0], m_offset[1]};
-
- CRect rcclip(0, 0, w, h);
-
- /* FIXME: startx/y looks to be wrong in the sample I tested (yes, this one too!)
- CPoint pt(m_sphli.StartX, m_sphli.StartY);
- CRect rc(pt, CPoint(m_sphli.StopX, m_sphli.StopY));
- */
-
- CSize size(m_sphli.StopX - m_sphli.StartX, m_sphli.StopY - m_sphli.StartY);
- CPoint pt((rcclip.Width() - size.cx) / 2, (rcclip.Height() * 3 - size.cy * 1) / 4);
- CRect rc(pt, size);
-
- int nField = 0;
- int n = 3;
-
- DWORD end[2] = {offset[1], (p[2] << 8) | p[3]};
-
- while ((nField == 0 && offset[0] < end[0]) || (nField == 1 && offset[1] < end[1])) {
- BYTE code = GetHalfNibble(p, offset, nField, n);
- BYTE repeat = 1 + (code == 0 ? GetHalfNibble(p, offset, nField, n) : 0);
-
- DrawPixels(yuv, w, pt, repeat, m_sppal[code & 3], rcclip);
- if ((pt.x += repeat) < rc.right) {
- continue;
- }
-
- while (n != 3) {
- GetHalfNibble(p, offset, nField, n); // align to byte
- }
-
- pt.x = rc.left;
- pt.y++;
- nField = 1 - nField;
- }
-}
-
-//
-// CClosedCaptionOutputPin
-//
-
-CClosedCaptionOutputPin::CClosedCaptionOutputPin(CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr)
- : CBaseOutputPin(NAME("CClosedCaptionOutputPin"), pFilter, pLock, phr, L"~CC")
-{
-}
-
-HRESULT CClosedCaptionOutputPin::CheckMediaType(const CMediaType* mtOut)
-{
- return mtOut->majortype == MEDIATYPE_AUXLine21Data && mtOut->subtype == MEDIASUBTYPE_Line21_GOPPacket
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
-}
-
-HRESULT CClosedCaptionOutputPin::GetMediaType(int iPosition, CMediaType* pmt)
-{
- if (iPosition < 0) {
- return E_INVALIDARG;
- }
- if (iPosition > 0) {
- return VFW_S_NO_MORE_ITEMS;
- }
-
- pmt->InitMediaType();
- pmt->majortype = MEDIATYPE_AUXLine21Data;
- pmt->subtype = MEDIASUBTYPE_Line21_GOPPacket;
- pmt->formattype = FORMAT_None;
-
- return S_OK;
-}
-
-HRESULT CClosedCaptionOutputPin::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties)
-{
- pProperties->cBuffers = 1;
- pProperties->cbBuffer = 2048;
- pProperties->cbAlign = 1;
- pProperties->cbPrefix = 0;
-
- HRESULT hr;
- ALLOCATOR_PROPERTIES Actual;
- if (FAILED(hr = pAllocator->SetProperties(pProperties, &Actual))) {
- return hr;
- }
-
- return pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer
- ? E_FAIL
- : NOERROR;
-}
-
-HRESULT CClosedCaptionOutputPin::Deliver(const void* ptr, int len)
-{
- HRESULT hr = S_FALSE;
-
- if (len > 4 && ptr && *(DWORD*)ptr == 0xf8014343 && IsConnected()) {
- CComPtr<IMediaSample> pSample;
- GetDeliveryBuffer(&pSample, nullptr, nullptr, 0);
- BYTE* pData = nullptr;
- pSample->GetPointer(&pData);
- *(DWORD*)pData = 0xb2010000;
- memcpy(pData + 4, ptr, len);
- pSample->SetActualDataLength(len + 4);
- hr = __super::Deliver(pSample);
- }
-
- return hr;
-}
diff --git a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.def b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.def
deleted file mode 100644
index 6492e5cd6..000000000
--- a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.def
+++ /dev/null
@@ -1,5 +0,0 @@
-EXPORTS
- DllCanUnloadNow PRIVATE
- DllGetClassObject PRIVATE
- DllRegisterServer PRIVATE
- DllUnregisterServer PRIVATE
diff --git a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.h b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.h
deleted file mode 100644
index aa48e2ab8..000000000
--- a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.h
+++ /dev/null
@@ -1,329 +0,0 @@
-/*
- * (C) 2003-2006 Gabest
- * (C) 2006-2013 see Authors.txt
- *
- * This file is part of MPC-HC.
- *
- * MPC-HC 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 3 of the License, or
- * (at your option) any later version.
- *
- * MPC-HC 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 this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#pragma once
-
-#include <atlcoll.h>
-#include <videoacc.h>
-#include "../../../DeCSS/DeCSSInputPin.h"
-#include "../BaseVideoFilter/BaseVideoFilter.h"
-#include "IMpeg2DecFilter.h"
-#include "Mpeg2DecSettingsWnd.h"
-
-#ifdef MPEG2ONLY
-#define Mpeg2DecFilterName L"MPC MPEG-2 Video Decoder"
-#else
-#define Mpeg2DecFilterName L"MPC MPEG Video Decoder"
-#endif
-
-class CSubpicInputPin;
-class CClosedCaptionOutputPin;
-class CMpeg2Dec;
-
-class __declspec(uuid("39F498AF-1A09-4275-B193-673B0BA3D478"))
- CMpeg2DecFilter
- : public CBaseVideoFilter
- , public IMpeg2DecFilter
- , public ISpecifyPropertyPages2
-{
- CSubpicInputPin* m_pSubpicInput;
- CClosedCaptionOutputPin* m_pClosedCaptionOutput;
-
- CAutoPtr<CMpeg2Dec> m_dec;
-
- REFERENCE_TIME m_AvgTimePerFrame;
- bool m_fWaitForKeyFrame;
- bool m_fInitializedBuffer;
- CSize m_par;
-
- struct framebuf {
- int w, h, pitch;
- BYTE* buf_base;
- BYTE* buf[6];
- REFERENCE_TIME rtStart, rtStop;
- DWORD flags;
- ditype di;
- framebuf()
- : di(DIAuto) {
- w = h = pitch = 0;
- buf_base = nullptr;
- ZeroMemory(&buf, sizeof(buf));
- rtStart = rtStop = 0;
- flags = 0;
- }
- ~framebuf() {
- Free();
- }
- void Alloc(int w, int h, int pitch) {
- Free(); // Ensure there is no memory leak
- this->w = w;
- this->h = h;
- this->pitch = pitch;
- int size = pitch * h;
- buf_base = (BYTE*)_aligned_malloc(size * 3 + 6 * 32, 32);
- BYTE* p = buf_base;
- buf[0] = p;
- p += (size + 31) & ~31;
- buf[3] = p;
- p += (size + 31) & ~31;
- buf[1] = p;
- p += (size / 4 + 31) & ~31;
- buf[4] = p;
- p += (size / 4 + 31) & ~31;
- buf[2] = p;
- p += (size / 4 + 31) & ~31;
- buf[5] = p;
- p += (size / 4 + 31) & ~31;
- }
- void Free() {
- if (buf_base) {
- _aligned_free(buf_base);
- }
- buf_base = nullptr;
- }
- } m_fb;
-
- bool m_fFilm;
- void SetDeinterlaceMethod();
- void SetTypeSpecificFlags(IMediaSample* pMS);
-
- AM_SimpleRateChange m_rate;
-
-protected:
- void InputTypeChanged();
- HRESULT Transform(IMediaSample* pIn);
- bool IsVideoInterlaced();
- void UpdateAspectRatio();
-
-public:
- CMpeg2DecFilter(LPUNKNOWN lpunk, HRESULT* phr);
- virtual ~CMpeg2DecFilter();
-
- virtual void GetOutputSize(int& w, int& h, int& arx, int& ary, int& RealWidth, int& RealHeight);
-
- DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
-
- HRESULT DeliverFast();
- HRESULT DeliverNormal();
- HRESULT Deliver(bool fRepeatLast);
-
- int GetPinCount();
- CBasePin* GetPin(int n);
-
- HRESULT EndOfStream();
- HRESULT BeginFlush();
- HRESULT EndFlush();
- HRESULT NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
-
- HRESULT CheckConnect(PIN_DIRECTION dir, IPin* pPin);
- HRESULT CheckInputType(const CMediaType* mtIn);
- HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);
- HRESULT SetMediaType(PIN_DIRECTION dir, const CMediaType* pmt);
-
- HRESULT StartStreaming();
- HRESULT StopStreaming();
-
- bool m_fDropFrames;
- HRESULT AlterQuality(Quality q);
-
-protected:
- CCritSec m_csProps;
- ditype m_ditype;
- float m_bright, m_cont, m_hue, m_sat;
- BYTE m_YTbl[256], m_UTbl[256 * 256], m_VTbl[256 * 256];
- bool m_fForcedSubs;
- bool m_fPlanarYUV;
- bool m_fInterlaced;
- bool m_bReadARFromStream;
-
- static void CalcBrCont(BYTE* YTbl, float bright, float cont);
- static void CalcHueSat(BYTE* UTbl, BYTE* VTbl, float hue, float sat);
- void ApplyBrContHueSat(BYTE* srcy, BYTE* srcu, BYTE* srcv, int w, int h, int pitch);
-
-public:
-
- // ISpecifyPropertyPages2
-
- STDMETHODIMP GetPages(CAUUID* pPages);
- STDMETHODIMP CreatePage(const GUID& guid, IPropertyPage** ppPage);
-
- // IMpeg2DecFilter
-
- STDMETHODIMP SetDeinterlaceMethod(ditype di);
- STDMETHODIMP_(ditype) GetDeinterlaceMethod();
-
- STDMETHODIMP SetBrightness(float bright);
- STDMETHODIMP SetContrast(float cont);
- STDMETHODIMP SetHue(float hue);
- STDMETHODIMP SetSaturation(float sat);
- STDMETHODIMP_(float) GetBrightness();
- STDMETHODIMP_(float) GetContrast();
- STDMETHODIMP_(float) GetHue();
- STDMETHODIMP_(float) GetSaturation();
-
- STDMETHODIMP EnableForcedSubtitles(bool fEnable);
- STDMETHODIMP_(bool) IsForcedSubtitlesEnabled();
-
- STDMETHODIMP EnablePlanarYUV(bool fEnable);
- STDMETHODIMP_(bool) IsPlanarYUVEnabled();
- STDMETHODIMP Apply();
- // IMpeg2DecFilter2
-
- STDMETHODIMP EnableInterlaced(bool fEnable);
- STDMETHODIMP_(bool) IsInterlacedEnabled();
-
- STDMETHODIMP EnableReadARFromStream(bool fEnable);
- STDMETHODIMP_(bool) IsReadARFromStreamEnabled();
-};
-
-class CMpeg2DecInputPin : public CDeCSSInputPin
-{
- LONG m_CorrectTS;
-
-public:
- CMpeg2DecInputPin(CTransformFilter* pFilter, HRESULT* phr, LPWSTR pName);
-
- CCritSec m_csRateLock;
- AM_SimpleRateChange m_ratechange;
-
- // IKsPropertySet
- STDMETHODIMP Set(REFGUID PropSet, ULONG Id, LPVOID InstanceData, ULONG InstanceLength, LPVOID PropertyData, ULONG DataLength);
- STDMETHODIMP Get(REFGUID PropSet, ULONG Id, LPVOID InstanceData, ULONG InstanceLength, LPVOID PropertyData, ULONG DataLength, ULONG* pBytesReturned);
- STDMETHODIMP QuerySupported(REFGUID PropSet, ULONG Id, ULONG* pTypeSupport);
-};
-
-class CMpeg2DecOutputPin : public CBaseVideoOutputPin
-{
-public:
- CMpeg2DecOutputPin(CBaseVideoFilter* pFilter, HRESULT* phr, LPWSTR pName);
-
- CAutoPtr<COutputQueue> m_pOutputQueue;
-
- HRESULT Active();
- HRESULT Inactive();
-
- HRESULT Deliver(IMediaSample* pMediaSample);
- HRESULT DeliverEndOfStream();
- HRESULT DeliverBeginFlush();
- HRESULT DeliverEndFlush();
- HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
-};
-
-class CSubpicInputPin : public CMpeg2DecInputPin
-{
- CCritSec m_csReceive;
-
- AM_PROPERTY_COMPOSIT_ON m_spon;
- AM_DVD_YUV m_sppal[16];
- bool m_fsppal;
- CAutoPtr<AM_PROPERTY_SPHLI> m_sphli; // temp
-
- class spu : public CAtlArray<BYTE>
- {
- public:
- bool m_fForced;
- REFERENCE_TIME m_rtStart, m_rtStop;
- DWORD m_offset[2];
- AM_PROPERTY_SPHLI m_sphli; // parsed
- CAutoPtr<AM_PROPERTY_SPHLI> m_psphli; // for the menu (optional)
- spu() {
- ZeroMemory(&m_sphli, sizeof(m_sphli));
- m_fForced = false;
- m_rtStart = m_rtStop = 0;
- }
- virtual ~spu() {}
- virtual bool Parse() = 0;
- virtual void Render(REFERENCE_TIME rt, BYTE** p, int w, int h, AM_DVD_YUV* sppal, bool fsppal) = 0;
- };
-
- class dvdspu : public spu
- {
- public:
- struct offset_t {
- REFERENCE_TIME rt;
- AM_PROPERTY_SPHLI sphli;
- };
- CAtlList<offset_t> m_offsets;
- bool Parse();
- void Render(REFERENCE_TIME rt, BYTE** p, int w, int h, AM_DVD_YUV* sppal, bool fsppal);
- };
-
- class cvdspu : public spu
- {
- public:
- AM_DVD_YUV m_sppal[2][4];
- cvdspu() {
- ZeroMemory(m_sppal, sizeof(m_sppal));
- }
- bool Parse();
- void Render(REFERENCE_TIME rt, BYTE** p, int w, int h, AM_DVD_YUV* sppal, bool fsppal);
- };
-
- class svcdspu : public spu
- {
- public:
- AM_DVD_YUV m_sppal[4];
- svcdspu() {
- ZeroMemory(m_sppal, sizeof(m_sppal));
- }
- bool Parse();
- void Render(REFERENCE_TIME rt, BYTE** p, int w, int h, AM_DVD_YUV* sppal, bool fsppal);
- };
-
- CAutoPtrList<spu> m_sps;
-
-protected:
- HRESULT Transform(IMediaSample* pSample);
-
-public:
- CSubpicInputPin(CTransformFilter* pFilter, HRESULT* phr);
-
- bool HasAnythingToRender(REFERENCE_TIME rt);
- void RenderSubpics(REFERENCE_TIME rt, BYTE** p, int w, int h);
-
- HRESULT CheckMediaType(const CMediaType* mtIn);
- HRESULT SetMediaType(const CMediaType* mtIn);
-
- // we shouldn't pass these to the filter from this pin
- STDMETHODIMP EndOfStream() { return S_OK; }
- STDMETHODIMP BeginFlush() { return S_OK; }
- STDMETHODIMP EndFlush();
- STDMETHODIMP NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) { return S_OK; }
-
- // IKsPropertySet
- STDMETHODIMP Set(REFGUID PropSet, ULONG Id, LPVOID InstanceData, ULONG InstanceLength, LPVOID PropertyData, ULONG DataLength);
- STDMETHODIMP QuerySupported(REFGUID PropSet, ULONG Id, ULONG* pTypeSupport);
-};
-
-class CClosedCaptionOutputPin : public CBaseOutputPin
-{
-public:
- CClosedCaptionOutputPin(CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr);
-
- HRESULT CheckMediaType(const CMediaType* mtOut);
- HRESULT GetMediaType(int iPosition, CMediaType* pmt);
- HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
-
- CMediaType& CurrentMediaType() { return m_mt; }
-
- HRESULT Deliver(const void* ptr, int len);
-};
diff --git a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.rc b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.rc
deleted file mode 100644
index 0a5b8560f..000000000
--- a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.rc
+++ /dev/null
@@ -1,124 +0,0 @@
-// Microsoft Visual C++ generated resource script.
-//
-#include "resource.h"
-#include "version.h"
-
-#define APSTUDIO_READONLY_SYMBOLS
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 2 resource.
-//
-#include "afxres.h"
-
-/////////////////////////////////////////////////////////////////////////////
-#undef APSTUDIO_READONLY_SYMBOLS
-
-/////////////////////////////////////////////////////////////////////////////
-// English (United States) resources
-
-#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
-LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
-#pragma code_page(1252)
-
-#ifdef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// TEXTINCLUDE
-//
-
-1 TEXTINCLUDE
-BEGIN
- "resource.h\0"
-END
-
-2 TEXTINCLUDE
-BEGIN
- "#include ""afxres.h""\r\n"
- "\0"
-END
-
-3 TEXTINCLUDE
-BEGIN
- "\r\n"
- "\0"
-END
-
-#endif // APSTUDIO_INVOKED
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// Version
-//
-
-VS_VERSION_INFO VERSIONINFO
- FILEVERSION MPC_VERSION_NUM
- PRODUCTVERSION MPC_VERSION_NUM
- FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
-#ifdef _DEBUG
- FILEFLAGS VS_FF_DEBUG
-#else
- FILEFLAGS 0x0L
-#endif
- FILEOS VOS_NT_WINDOWS32
- FILETYPE VFT_DLL
- FILESUBTYPE VFT2_UNKNOWN
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "040904b0"
- BEGIN
- VALUE "Comments", MPC_VERSION_COMMENTS
- VALUE "CompanyName", MPC_COMP_NAME_STR
- VALUE "FileDescription", "MPEG-2 Decoder Filter for DirectShow"
- VALUE "FileVersion", MPC_VERSION_STR_FULL
- VALUE "InternalName", "Mpeg2Dec Filter"
- VALUE "LegalCopyright", MPC_COPYRIGHT_STR
- VALUE "OriginalFilename", "Mpeg2DecFilter.ax"
- VALUE "ProductName", "Mpeg2Dec Filter"
- VALUE "ProductVersion", MPC_VERSION_STR_FULL
- END
- END
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x409, 1200
- END
-END
-
-
-/////////////////////////////////////////////////////////////////////////////
-//
-// String Table
-//
-
-STRINGTABLE
-BEGIN
- IDS_FILTER_SETTINGS_CAPTION "Settings"
- IDS_MPEG2_ENABLE_PLANAR "Enable planar YUV media types (VY12, I420, IYUY)"
- IDS_MPEG2_INTERLACE_FLAG "Set interlaced flag in output media type"
- IDS_MPEG2_FORCED_SUBS "Always display forced subtitles"
- IDS_MPEG2_DEINTERLACING "Deinterlacing"
- IDS_MPEG2_BRIGHTNESS "Brightness"
- IDS_MPEG2_RESET "Reset"
- IDS_MPEG2_NOTE1 "Note: Using a non-planar output format, bob deinterlacer, or adjusting color properies can degrade performance. ""Auto"" deinterlacer will switch to ""Blend"" when necessary."
- IDS_MPEG2_CONTRAST "Contrast"
- IDS_MPEG2_HUE "Hue"
- IDS_MPEG2_SATURATION "Saturation"
- IDS_MPEG2_READ_AR "Read AR from stream"
-END
-
-#endif // English (United States) resources
-/////////////////////////////////////////////////////////////////////////////
-
-
-
-#ifndef APSTUDIO_INVOKED
-/////////////////////////////////////////////////////////////////////////////
-//
-// Generated from the TEXTINCLUDE 3 resource.
-//
-
-
-/////////////////////////////////////////////////////////////////////////////
-#endif // not APSTUDIO_INVOKED
-
diff --git a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.vcxproj b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.vcxproj
deleted file mode 100644
index 573c6b3f0..000000000
--- a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.vcxproj
+++ /dev/null
@@ -1,277 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ItemGroup Label="ProjectConfigurations">
- <ProjectConfiguration Include="Debug Filter|Win32">
- <Configuration>Debug Filter</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Debug Filter|x64">
- <Configuration>Debug Filter</Configuration>
- <Platform>x64</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Debug|Win32">
- <Configuration>Debug</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Debug|x64">
- <Configuration>Debug</Configuration>
- <Platform>x64</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release Filter|Win32">
- <Configuration>Release Filter</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release Filter|x64">
- <Configuration>Release Filter</Configuration>
- <Platform>x64</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|Win32">
- <Configuration>Release</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|x64">
- <Configuration>Release</Configuration>
- <Platform>x64</Platform>
- </ProjectConfiguration>
- </ItemGroup>
- <PropertyGroup Label="Globals">
- <ProjectGuid>{305BAB2D-0D75-4FBC-8BCD-A2917392B48C}</ProjectGuid>
- <RootNamespace>Mpeg2DecFilter</RootNamespace>
- <Keyword>MFCProj</Keyword>
- <ProjectName>Mpeg2DecFilter</ProjectName>
- </PropertyGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
- <Import Project="..\..\..\platform.props" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
- <ConfigurationType>StaticLibrary</ConfigurationType>
- <UseOfMfc>Static</UseOfMfc>
- <CharacterSet>Unicode</CharacterSet>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
- <ConfigurationType>StaticLibrary</ConfigurationType>
- <UseOfMfc>Static</UseOfMfc>
- <CharacterSet>Unicode</CharacterSet>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Filter|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
- <UseOfMfc>Static</UseOfMfc>
- <CharacterSet>Unicode</CharacterSet>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Filter|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
- <UseOfMfc>Static</UseOfMfc>
- <CharacterSet>Unicode</CharacterSet>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
- <ConfigurationType>StaticLibrary</ConfigurationType>
- <UseOfMfc>Static</UseOfMfc>
- <CharacterSet>Unicode</CharacterSet>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
- <ConfigurationType>StaticLibrary</ConfigurationType>
- <UseOfMfc>Static</UseOfMfc>
- <CharacterSet>Unicode</CharacterSet>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Filter|x64'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
- <UseOfMfc>Static</UseOfMfc>
- <CharacterSet>Unicode</CharacterSet>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Filter|x64'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
- <UseOfMfc>Static</UseOfMfc>
- <CharacterSet>Unicode</CharacterSet>
- </PropertyGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
- <ImportGroup Label="ExtensionSettings">
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="..\..\..\common.props" />
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="..\..\..\common.props" />
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Filter|Win32'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="..\..\..\common.props" />
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Filter|Win32'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="..\..\..\common.props" />
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="..\..\..\common.props" />
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="..\..\..\common.props" />
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Filter|x64'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="..\..\..\common.props" />
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Filter|x64'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="..\..\..\common.props" />
- </ImportGroup>
- <PropertyGroup Label="UserMacros" />
- <PropertyGroup>
- <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
- <TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug Filter|Win32'">.ax</TargetExt>
- <TargetExt Condition="'$(Configuration)|$(Platform)'=='Release Filter|Win32'">.ax</TargetExt>
- <TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug Filter|x64'">.ax</TargetExt>
- <TargetExt Condition="'$(Configuration)|$(Platform)'=='Release Filter|x64'">.ax</TargetExt>
- </PropertyGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Filter|Win32'">
- <ClCompile>
- <AdditionalIncludeDirectories>..\..\..\..\include;..\..\..\thirdparty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- </ClCompile>
- <Link>
- <AdditionalDependencies>detours.lib;idct_mmx.obj;motion_comp_mmx.obj;Vfw32.lib;%(AdditionalDependencies)</AdditionalDependencies>
- <AdditionalLibraryDirectories>$(SolutionDir)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
- <IgnoreSpecificDefaultLibraries>LIBCMT;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
- <ModuleDefinitionFile>Mpeg2DecFilter.def</ModuleDefinitionFile>
- <ImageHasSafeExceptionHandlers Condition="'$(PlatformToolsetVersion)'=='110'">false</ImageHasSafeExceptionHandlers>
- </Link>
- <ResourceCompile>
- <AdditionalIncludeDirectories>..\..\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- </ResourceCompile>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Filter|x64'">
- <ClCompile>
- <AdditionalIncludeDirectories>..\..\..\..\include;..\..\..\thirdparty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- </ClCompile>
- <Link>
- <AdditionalLibraryDirectories>$(SolutionDir)lib64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
- <ImageHasSafeExceptionHandlers Condition="'$(PlatformToolsetVersion)'=='110'">false</ImageHasSafeExceptionHandlers>
- </Link>
- <ResourceCompile>
- <AdditionalIncludeDirectories>..\..\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- </ResourceCompile>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Filter|Win32'">
- <ClCompile>
- <AdditionalIncludeDirectories>..\..\..\..\include;..\..\..\thirdparty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>MPEG2ONLY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- <Link>
- <AdditionalDependencies>detours.lib;idct_mmx.obj;motion_comp_mmx.obj;Vfw32.lib;%(AdditionalDependencies)</AdditionalDependencies>
- <AdditionalLibraryDirectories>$(SolutionDir)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
- <ModuleDefinitionFile>Mpeg2DecFilter.def</ModuleDefinitionFile>
- <ImageHasSafeExceptionHandlers Condition="'$(PlatformToolsetVersion)'=='110'">false</ImageHasSafeExceptionHandlers>
- </Link>
- <ResourceCompile>
- <AdditionalIncludeDirectories>..\..\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- </ResourceCompile>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Filter|x64'">
- <ClCompile>
- <AdditionalIncludeDirectories>..\..\..\..\include;..\..\..\thirdparty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>MPEG2ONLY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- <Link>
- <AdditionalLibraryDirectories>$(SolutionDir)lib64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
- <ImageHasSafeExceptionHandlers Condition="'$(PlatformToolsetVersion)'=='110'">false</ImageHasSafeExceptionHandlers>
- </Link>
- <ResourceCompile>
- <AdditionalIncludeDirectories>..\..\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- </ResourceCompile>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <ClCompile>
- <AdditionalIncludeDirectories>..\..\..\..\include;..\..\..\thirdparty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- <Lib>
- <AdditionalDependencies>idct_mmx.obj;motion_comp_mmx.obj;%(AdditionalDependencies)</AdditionalDependencies>
- </Lib>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
- <ClCompile>
- <AdditionalIncludeDirectories>..\..\..\..\include;..\..\..\thirdparty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <ClCompile>
- <AdditionalIncludeDirectories>..\..\..\..\include;..\..\..\thirdparty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- <Lib>
- <AdditionalDependencies>idct_mmx.obj;motion_comp_mmx.obj;%(AdditionalDependencies)</AdditionalDependencies>
- </Lib>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
- <ClCompile>
- <AdditionalIncludeDirectories>..\..\..\..\include;..\..\..\thirdparty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- </ItemDefinitionGroup>
- <ItemGroup>
- <ClCompile Include="..\..\..\thirdparty\mfc\afxctrlcontainer.cpp">
- <ExcludedFromBuild Condition="'$(Configuration)'=='Debug' or '$(Configuration)'=='Release' or '$(PlatformToolsetVersion)'=='110'">true</ExcludedFromBuild>
- </ClCompile>
- <ClCompile Include="..\..\..\thirdparty\mfc\afxglobals.cpp">
- <ExcludedFromBuild Condition="'$(Configuration)'=='Debug' or '$(Configuration)'=='Release' or '$(PlatformToolsetVersion)'=='110'">true</ExcludedFromBuild>
- </ClCompile>
- <ClCompile Include="..\..\..\thirdparty\mfc\winmdi.cpp">
- <ExcludedFromBuild Condition="'$(Configuration)'=='Debug' or '$(Configuration)'=='Release' or '$(PlatformToolsetVersion)'=='110'">true</ExcludedFromBuild>
- </ClCompile>
- <ClCompile Include="idct_sse2.cpp" />
- <ClCompile Include="libmpeg2.cpp" />
- <ClCompile Include="mc_sse2.cpp" />
- <ClCompile Include="Mpeg2DecFilter.cpp" />
- <ClCompile Include="Mpeg2DecSettingsWnd.cpp" />
- <ClCompile Include="stdafx.cpp">
- <PrecompiledHeader>Create</PrecompiledHeader>
- </ClCompile>
- </ItemGroup>
- <ItemGroup>
- <ClInclude Include="attributes.h" />
- <ClInclude Include="IMpeg2DecFilter.h" />
- <ClInclude Include="libmpeg2.h" />
- <ClInclude Include="Mpeg2DecFilter.h" />
- <ClInclude Include="Mpeg2DecSettingsWnd.h" />
- <ClInclude Include="resource.h">
- <ExcludedFromBuild Condition="'$(Configuration)'=='Debug' or '$(Configuration)'=='Release'">true</ExcludedFromBuild>
- </ClInclude>
- <ClInclude Include="..\..\..\DSUtil\simd.h" />
- <ClInclude Include="..\..\..\DSUtil\simd_common.h" />
- <ClInclude Include="..\..\..\DSUtil\simd_instructions.h" />
- <ClInclude Include="stdafx.h" />
- </ItemGroup>
- <ItemGroup>
- <ResourceCompile Include="Mpeg2DecFilter.rc">
- <ExcludedFromBuild Condition="'$(Configuration)'=='Debug' or '$(Configuration)'=='Release'">true</ExcludedFromBuild>
- </ResourceCompile>
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\..\..\DeCSS\DeCSS.vcxproj">
- <Project>{1a2dfd1a-3c6c-44d1-909d-294af646b575}</Project>
- </ProjectReference>
- <ProjectReference Include="..\..\..\DSUtil\DSUtil.vcxproj">
- <Project>{fc70988b-1ae5-4381-866d-4f405e28ac42}</Project>
- </ProjectReference>
- <ProjectReference Include="..\..\..\thirdparty\VirtualDub\Kasumi\Kasumi.vcxproj">
- <Project>{0d252872-7542-4232-8d02-53f9182aee15}</Project>
- </ProjectReference>
- <ProjectReference Include="..\..\..\thirdparty\VirtualDub\system\system.vcxproj">
- <Project>{c2082189-3ecb-4079-91fa-89d3c8a305c0}</Project>
- </ProjectReference>
- <ProjectReference Include="..\..\..\thirdparty\BaseClasses\BaseClasses.vcxproj">
- <Project>{e8a3f6fa-ae1c-4c8e-a0b6-9c8480324eaa}</Project>
- </ProjectReference>
- <ProjectReference Include="..\..\Filters.vcxproj">
- <Project>{273b3149-3192-4b75-a791-470320b90812}</Project>
- </ProjectReference>
- <ProjectReference Include="..\BaseVideoFilter\BaseVideoFilter.vcxproj">
- <Project>{54dda60f-e528-4d07-a152-960a1e818680}</Project>
- </ProjectReference>
- </ItemGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
- <ImportGroup Label="ExtensionTargets">
- </ImportGroup>
-</Project> \ No newline at end of file
diff --git a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.vcxproj.filters b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.vcxproj.filters
deleted file mode 100644
index 54d431f5f..000000000
--- a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.vcxproj.filters
+++ /dev/null
@@ -1,83 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ItemGroup>
- <Filter Include="Source Files">
- <UniqueIdentifier>{fbdabc83-2c4a-4281-b29b-3deb304adccb}</UniqueIdentifier>
- <Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm</Extensions>
- </Filter>
- <Filter Include="Header Files">
- <UniqueIdentifier>{414034fb-1cd9-46a4-96c8-07498ccee353}</UniqueIdentifier>
- <Extensions>h;hpp;hxx;hm;inl;inc</Extensions>
- </Filter>
- <Filter Include="Resource Files">
- <UniqueIdentifier>{135298f9-de49-4e12-a042-b10b9c34a459}</UniqueIdentifier>
- <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
- </Filter>
- </ItemGroup>
- <ItemGroup>
- <ClCompile Include="idct_sse2.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="libmpeg2.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="mc_sse2.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="Mpeg2DecFilter.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="Mpeg2DecSettingsWnd.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="stdafx.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="..\..\..\thirdparty\mfc\afxctrlcontainer.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="..\..\..\thirdparty\mfc\afxglobals.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="..\..\..\thirdparty\mfc\winmdi.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- </ItemGroup>
- <ItemGroup>
- <ClInclude Include="attributes.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="IMpeg2DecFilter.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="libmpeg2.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="Mpeg2DecFilter.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="Mpeg2DecSettingsWnd.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="resource.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="..\..\..\DSUtil\simd.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="..\..\..\DSUtil\simd_common.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="..\..\..\DSUtil\simd_instructions.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="stdafx.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- </ItemGroup>
- <ItemGroup>
- <ResourceCompile Include="Mpeg2DecFilter.rc">
- <Filter>Resource Files</Filter>
- </ResourceCompile>
- </ItemGroup>
-</Project> \ No newline at end of file
diff --git a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.cpp b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.cpp
deleted file mode 100644
index d0c054a59..000000000
--- a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.cpp
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * (C) 2003-2006 Gabest
- * (C) 2006-2012 see Authors.txt
- *
- * This file is part of MPC-HC.
- *
- * MPC-HC 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 3 of the License, or
- * (at your option) any later version.
- *
- * MPC-HC 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 this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "stdafx.h"
-#include "resource.h"
-#include "Mpeg2DecSettingsWnd.h"
-#include "../../../DSUtil/DSUtil.h"
-
-
-//
-// CMpeg2DecSettingsWnd
-//
-
-static TCHAR m_strBrightness[100];
-static TCHAR m_strContrast[100];
-static TCHAR m_strHue[100];
-static TCHAR m_strSaturation[100];
-
-CMpeg2DecSettingsWnd::CMpeg2DecSettingsWnd()
-{
- wcscpy_s(m_strBrightness, ResStr(IDS_MPEG2_BRIGHTNESS));
- wcscpy_s(m_strContrast, ResStr(IDS_MPEG2_CONTRAST));
- wcscpy_s(m_strHue, ResStr(IDS_MPEG2_HUE));
- wcscpy_s(m_strSaturation, ResStr(IDS_MPEG2_SATURATION));
-}
-
-bool CMpeg2DecSettingsWnd::OnConnect(const CInterfaceList<IUnknown, &IID_IUnknown>& pUnks)
-{
- ASSERT(!m_pM2DF);
-
- m_pM2DF.Release();
-
- POSITION pos = pUnks.GetHeadPosition();
- while (pos && !(m_pM2DF = pUnks.GetNext(pos))) {
- ;
- }
-
- if (!m_pM2DF) {
- return false;
- }
-
- m_ditype = m_pM2DF->GetDeinterlaceMethod();
- m_procamp[0] = m_pM2DF->GetBrightness();
- m_procamp[1] = m_pM2DF->GetContrast();
- m_procamp[2] = m_pM2DF->GetHue();
- m_procamp[3] = m_pM2DF->GetSaturation();
- m_forcedsubs = m_pM2DF->IsForcedSubtitlesEnabled();
- m_planaryuv = m_pM2DF->IsPlanarYUVEnabled();
- m_interlaced = m_pM2DF->IsInterlacedEnabled();
- m_readARFromStream = m_pM2DF->IsReadARFromStreamEnabled();
-
- return true;
-}
-
-void CMpeg2DecSettingsWnd::OnDisconnect()
-{
- m_pM2DF.Release();
-}
-
-bool CMpeg2DecSettingsWnd::OnActivate()
-{
- ASSERT(IPP_FONTSIZE == 13);
- const int h20 = IPP_SCALE(20);
- const int h25 = IPP_SCALE(25);
- DWORD dwStyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP;
- CPoint p(10, 10);
-
- m_planaryuv_check.Create(ResStr(IDS_MPEG2_ENABLE_PLANAR), dwStyle | BS_AUTOCHECKBOX, CRect(p, CSize(IPP_SCALE(300), m_fontheight)), this, IDC_PP_CHECK1);
- m_planaryuv_check.SetCheck(m_planaryuv ? BST_CHECKED : BST_UNCHECKED);
- p.y += h20;
-
- m_interlaced_check.Create(ResStr(IDS_MPEG2_INTERLACE_FLAG), dwStyle | BS_AUTOCHECKBOX, CRect(p, CSize(IPP_SCALE(300), m_fontheight)), this, IDC_PP_CHECK2);
- m_interlaced_check.SetCheck(m_interlaced ? BST_CHECKED : BST_UNCHECKED);
- p.y += h20;
-
- m_forcedsubs_check.Create(ResStr(IDS_MPEG2_FORCED_SUBS), dwStyle | BS_AUTOCHECKBOX, CRect(p, CSize(IPP_SCALE(300), m_fontheight)), this, IDC_PP_CHECK3);
- m_forcedsubs_check.SetCheck(m_forcedsubs ? BST_CHECKED : BST_UNCHECKED);
- p.y += h20;
-
- m_readARFromStream_check.Create(ResStr(IDS_MPEG2_READ_AR), dwStyle | BS_AUTOCHECKBOX, CRect(p, CSize(IPP_SCALE(300), m_fontheight)), this, IDC_PP_CHECK4);
- m_readARFromStream_check.SetCheck(m_readARFromStream ? BST_CHECKED : BST_UNCHECKED);
- p.y += h25;
-
- m_ditype_static.Create(ResStr(IDS_MPEG2_DEINTERLACING), WS_VISIBLE | WS_CHILD, CRect(p, CSize(IPP_SCALE(100), m_fontheight)), this);
- m_ditype_combo.Create(dwStyle | CBS_DROPDOWNLIST, CRect(p + CSize(IPP_SCALE(110), -4), CSize(IPP_SCALE(100), 200)), this, IDC_PP_COMBO1);
- m_ditype_combo.SetItemData(m_ditype_combo.AddString(_T("Auto")), (DWORD)DIAuto);
- m_ditype_combo.SetItemData(m_ditype_combo.AddString(_T("Weave")), (DWORD)DIWeave);
- m_ditype_combo.SetItemData(m_ditype_combo.AddString(_T("Blend")), (DWORD)DIBlend);
- m_ditype_combo.SetItemData(m_ditype_combo.AddString(_T("Bob")), (DWORD)DIBob);
- m_ditype_combo.SetItemData(m_ditype_combo.AddString(_T("Field Shift")), (DWORD)DIFieldShift);
- m_ditype_combo.SetItemData(m_ditype_combo.AddString(_T("ELA")), (DWORD)DIELA);
- m_ditype_combo.SetCurSel(0);
- for (int i = 0; i < m_ditype_combo.GetCount(); i++)
- if ((int)m_ditype_combo.GetItemData(i) == m_ditype) {
- m_ditype_combo.SetCurSel(i);
- }
- m_ditype_combo.EnableWindow(!IsDlgButtonChecked(m_interlaced_check.GetDlgCtrlID()));
- p.y += h25;
-
- {
- int h = max(21, m_fontheight); // special size for sliders
- static const TCHAR* labels[] = {m_strBrightness, m_strContrast, m_strHue, m_strSaturation};
- for (int i = 0; i < _countof(m_procamp_slider); i++) {
- m_procamp_static[i].Create(labels[i], WS_VISIBLE | WS_CHILD, CRect(p, CSize(IPP_SCALE(80), m_fontheight)), this);
- m_procamp_slider[i].Create(dwStyle, CRect(p + CPoint(IPP_SCALE(85), 0), CSize(201, h)), this, IDC_PP_SLIDER1 + i);
- m_procamp_value[i].Create(_T(""), WS_VISIBLE | WS_CHILD, CRect(p + CPoint(IPP_SCALE(85) + 201, 0), CSize(IPP_SCALE(30), m_fontheight)), this);
- p.y += h;
- }
- m_procamp_slider[0].SetRange(0, 2 * 128);
- m_procamp_slider[0].SetTic(128);
- m_procamp_slider[0].SetPos((int)(m_procamp[0] + (m_procamp[0] >= 0 ? 0.5f : -0.5f)) + 128);
- m_procamp_slider[1].SetRange(0, 200);
- m_procamp_slider[1].SetTic(100);
- m_procamp_slider[1].SetPos((int)(100 * m_procamp[1] + 0.5f));
- m_procamp_slider[2].SetRange(0, 2 * 180);
- m_procamp_slider[2].SetTic(180);
- m_procamp_slider[2].SetPos((int)(m_procamp[2] + (m_procamp[2] >= 0 ? 0.5f : -0.5f)) + 180);
- m_procamp_slider[3].SetRange(0, 200);
- m_procamp_slider[3].SetTic(100);
- m_procamp_slider[3].SetPos((int)(100 * m_procamp[3] + 0.5f));
- p.y += 5;
- m_procamp_tv2pc.Create(_T("TV->PC"), dwStyle, CRect(p + CPoint(IPP_SCALE(85) + 200 / 2 - 80 - 5, 0), CSize(80, m_fontheight + 6)), this, IDC_PP_BUTTON1);
- m_procamp_reset.Create(ResStr(IDS_MPEG2_RESET), dwStyle, CRect(p + CPoint(IPP_SCALE(85) + 200 / 2 + 6, 0), CSize(80, m_fontheight + 6)), this, IDC_PP_BUTTON2);
- p.y += h25;
-
- UpdateProcampValues();
- }
-
- m_note_static.Create(
- ResStr(IDS_MPEG2_NOTE1), WS_VISIBLE | WS_CHILD, CRect(p, CSize(IPP_SCALE(320), m_fontheight * 4)), this);
-
- for (CWnd* pWnd = GetWindow(GW_CHILD); pWnd; pWnd = pWnd->GetNextWindow()) {
- pWnd->SetFont(&m_font, FALSE);
- }
-
- return true;
-}
-
-void CMpeg2DecSettingsWnd::OnDeactivate()
-{
- m_ditype = (ditype)m_ditype_combo.GetItemData(m_ditype_combo.GetCurSel());
- m_procamp[0] = (float)m_procamp_slider[0].GetPos() - 128;
- m_procamp[1] = (float)m_procamp_slider[1].GetPos() / 100;
- m_procamp[2] = (float)m_procamp_slider[2].GetPos() - 180;
- m_procamp[3] = (float)m_procamp_slider[3].GetPos() / 100;
- m_planaryuv = !!IsDlgButtonChecked(m_planaryuv_check.GetDlgCtrlID());
- m_interlaced = !!IsDlgButtonChecked(m_interlaced_check.GetDlgCtrlID());
- m_forcedsubs = !!IsDlgButtonChecked(m_forcedsubs_check.GetDlgCtrlID());
- m_readARFromStream = !!IsDlgButtonChecked(m_readARFromStream_check.GetDlgCtrlID());
-}
-
-bool CMpeg2DecSettingsWnd::OnApply()
-{
- OnDeactivate();
-
- if (m_pM2DF) {
- m_pM2DF->SetDeinterlaceMethod(m_ditype);
- m_pM2DF->SetBrightness(m_procamp[0]);
- m_pM2DF->SetContrast(m_procamp[1]);
- m_pM2DF->SetHue(m_procamp[2]);
- m_pM2DF->SetSaturation(m_procamp[3]);
- m_pM2DF->EnableForcedSubtitles(m_forcedsubs);
- m_pM2DF->EnablePlanarYUV(m_planaryuv);
- m_pM2DF->EnableInterlaced(m_interlaced);
- m_pM2DF->EnableReadARFromStream(m_readARFromStream);
- m_pM2DF->Apply();
- }
-
- return true;
-}
-
-void CMpeg2DecSettingsWnd::UpdateProcampValues()
-{
- CString str;
-
- str.Format(_T("%d"), m_procamp_slider[0].GetPos() - 128);
- m_procamp_value[0].SetWindowText(str);
- str.Format(_T("%d%%"), m_procamp_slider[1].GetPos());
- m_procamp_value[1].SetWindowText(str);
- str.Format(_T("%d"), m_procamp_slider[2].GetPos() - 180);
- m_procamp_value[2].SetWindowText(str);
- str.Format(_T("%d%%"), m_procamp_slider[3].GetPos());
- m_procamp_value[3].SetWindowText(str);
-}
-
-BEGIN_MESSAGE_MAP(CMpeg2DecSettingsWnd, CInternalPropertyPageWnd)
- ON_BN_CLICKED(IDC_PP_BUTTON1, OnButtonProcampPc2Tv)
- ON_BN_CLICKED(IDC_PP_BUTTON2, OnButtonProcampReset)
- ON_BN_CLICKED(IDC_PP_CHECK2, OnButtonInterlaced)
- ON_WM_HSCROLL()
-END_MESSAGE_MAP()
-
-void CMpeg2DecSettingsWnd::OnButtonProcampPc2Tv()
-{
- m_procamp_slider[0].SetPos(128 - 16);
- m_procamp_slider[1].SetPos(100 * 255 / (235 - 16));
-
- UpdateProcampValues();
-}
-
-void CMpeg2DecSettingsWnd::OnButtonProcampReset()
-{
- m_procamp_slider[0].SetPos(128);
- m_procamp_slider[1].SetPos(100);
- m_procamp_slider[2].SetPos(180);
- m_procamp_slider[3].SetPos(100);
-
- UpdateProcampValues();
-}
-
-void CMpeg2DecSettingsWnd::OnButtonInterlaced()
-{
- m_ditype_combo.EnableWindow(!IsDlgButtonChecked(m_interlaced_check.GetDlgCtrlID()));
-}
-
-void CMpeg2DecSettingsWnd::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
-{
- UpdateProcampValues();
-
- __super::OnHScroll(nSBCode, nPos, pScrollBar);
-}
diff --git a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.h b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.h
deleted file mode 100644
index 5e5586887..000000000
--- a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * (C) 2003-2006 Gabest
- * (C) 2006-2013 see Authors.txt
- *
- * This file is part of MPC-HC.
- *
- * MPC-HC 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 3 of the License, or
- * (at your option) any later version.
- *
- * MPC-HC 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 this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#pragma once
-
-#include "../../InternalPropertyPage.h"
-#include "IMpeg2DecFilter.h"
-#include "resource.h"
-#include <afxcmn.h>
-
-class __declspec(uuid("E5FB6957-65E6-491B-BB37-B25C9FE3BEA7"))
- CMpeg2DecSettingsWnd : public CInternalPropertyPageWnd
-{
- CComQIPtr<IMpeg2DecFilter> m_pM2DF;
-
- ditype m_ditype;
- float m_procamp[4];
- bool m_planaryuv;
- bool m_interlaced;
- bool m_forcedsubs;
- bool m_readARFromStream;
-
- enum {
- IDC_PP_COMBO1 = 10000,
- IDC_PP_SLIDER1,
- IDC_PP_SLIDER2,
- IDC_PP_SLIDER3,
- IDC_PP_SLIDER4,
- IDC_PP_CHECK1,
- IDC_PP_CHECK2,
- IDC_PP_CHECK3,
- IDC_PP_CHECK4,
- IDC_PP_BUTTON1,
- IDC_PP_BUTTON2
- };
-
- CStatic m_ditype_static;
- CComboBox m_ditype_combo;
- CStatic m_procamp_static[4];
- CSliderCtrl m_procamp_slider[4];
- CStatic m_procamp_value[4];
- CButton m_procamp_tv2pc;
- CButton m_procamp_reset;
- CButton m_planaryuv_check;
- CButton m_interlaced_check;
- CButton m_forcedsubs_check;
- CButton m_readARFromStream_check;
- CStatic m_note_static;
-
- void UpdateProcampValues();
-
-public:
- CMpeg2DecSettingsWnd();
-
- bool OnConnect(const CInterfaceList<IUnknown, &IID_IUnknown>& pUnks);
- void OnDisconnect();
- bool OnActivate();
- void OnDeactivate();
- bool OnApply();
-
- static LPCTSTR GetWindowTitle() { return MAKEINTRESOURCE(IDS_FILTER_SETTINGS_CAPTION); }
- static CSize GetWindowSize() { return CSize(340, 296); }
-
- DECLARE_MESSAGE_MAP()
-
- afx_msg void OnButtonProcampPc2Tv();
- afx_msg void OnButtonProcampReset();
- afx_msg void OnButtonInterlaced();
- afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
-};
diff --git a/src/filters/transform/Mpeg2DecFilter/attributes.h b/src/filters/transform/Mpeg2DecFilter/attributes.h
deleted file mode 100644
index e587e158f..000000000
--- a/src/filters/transform/Mpeg2DecFilter/attributes.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * attributes.h
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
- * See http://libmpeg2.sourceforge.net/ for updates.
- *
- * mpeg2dec 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 of the License, or
- * (at your option) any later version.
- *
- * mpeg2dec 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef _ATTRIBUTES_H_
-#define _ATTRIBUTES_H_
-
-/* use gcc attribs to align critical data structures */
-#ifdef __GNUC__
- #define __align8(t,v) t v __attribute__ ((aligned (8)))
- #define __align16(t,v) t v __attribute__ ((aligned (16)))
-#else
- #define __align8(t,v) __declspec(align(8)) t v
- #define __align16(t,v) __declspec(align(16)) t v
-#endif
-
-#ifdef HAVE_BUILTIN_EXPECT
-#define likely(x) __builtin_expect ((x) != 0, 1)
-#define unlikely(x) __builtin_expect ((x) != 0, 0)
-#else
-#define likely(x) (x)
-#define unlikely(x) (x)
-#endif
-
-#endif
diff --git a/src/filters/transform/Mpeg2DecFilter/idct_mmx.obj b/src/filters/transform/Mpeg2DecFilter/idct_mmx.obj
deleted file mode 100644
index d5dcbe5aa..000000000
--- a/src/filters/transform/Mpeg2DecFilter/idct_mmx.obj
+++ /dev/null
Binary files differ
diff --git a/src/filters/transform/Mpeg2DecFilter/idct_sse2.cpp b/src/filters/transform/Mpeg2DecFilter/idct_sse2.cpp
deleted file mode 100644
index 9fa45900b..000000000
--- a/src/filters/transform/Mpeg2DecFilter/idct_sse2.cpp
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- * (C) 2003-2006 Gabest
- * (C) 2006-2013 see Authors.txt
- *
- * This file is part of MPC-HC.
- *
- * MPC-HC 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 3 of the License, or
- * (at your option) any later version.
- *
- * MPC-HC 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 this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "stdafx.h"
-#include <inttypes.h>
-#include "libmpeg2.h"
-#include "attributes.h"
-#include "../../../DSUtil/simd.h"
-
-// Intel's SSE2 implementation of iDCT
-// AP-945
-// http://cache-www.intel.com/cd/00/00/01/76/17680_w_idct.pdf
-
-static const int BITS_INV_ACC = 4;
-static const int SHIFT_INV_ROW = 16 - BITS_INV_ACC;
-static const int SHIFT_INV_COL = 1 + BITS_INV_ACC;
-static const int RND_INV_ROW = 1024 * (6 - BITS_INV_ACC);
-static const int RND_INV_COL = 16 * (BITS_INV_ACC - 3);
-static const int RND_INV_CORR = RND_INV_COL - 1;
-
-static __align16(const short, M128_round_inv_row[8]) = {RND_INV_ROW, 0, RND_INV_ROW, 0, RND_INV_ROW, 0, RND_INV_ROW, 0};
-static __align16(const short, M128_one_corr[8]) = {1, 1, 1, 1, 1, 1, 1, 1};
-static __align16(const short, M128_round_inv_col[8]) = {RND_INV_COL, RND_INV_COL, RND_INV_COL, RND_INV_COL, RND_INV_COL, RND_INV_COL, RND_INV_COL, RND_INV_COL};
-static __align16(const short, M128_round_inv_corr[8]) = {RND_INV_CORR, RND_INV_CORR, RND_INV_CORR, RND_INV_CORR, RND_INV_CORR, RND_INV_CORR, RND_INV_CORR, RND_INV_CORR};
-static __align16(const short, M128_tg_1_16[8]) = {13036, 13036, 13036, 13036, 13036, 13036, 13036, 13036}; // tg * (2<<16) + 0.5
-static __align16(const short, M128_tg_2_16[8]) = {27146, 27146, 27146, 27146, 27146, 27146, 27146, 27146}; // tg * (2<<16) + 0.5
-static __align16(const short, M128_tg_3_16[8]) = { -21746, -21746, -21746, -21746, -21746, -21746, -21746, -21746}; // tg * (2<<16) + 0.5
-static __align16(const short, M128_cos_4_16[8]) = { -19195, -19195, -19195, -19195, -19195, -19195, -19195, -19195}; // cos * (2<<16) + 0.5
-
-static __align16(const int16_t, M128_tab_i_04[]) = {16384, 21407, 16384, 8867, 16384, -8867, 16384, -21407, 16384, 8867, -16384, -21407, -16384, 21407, 16384, -8867, 22725, 19266, 19266, -4520, 12873, -22725, 4520, -12873, 12873, 4520, -22725, -12873, 4520, 19266, 19266, -22725};
-static __align16(const int16_t, M128_tab_i_17[]) = {22725, 29692, 22725, 12299, 22725, -12299, 22725, -29692, 22725, 12299, -22725, -29692, -22725, 29692, 22725, -12299, 31521, 26722, 26722, -6270, 17855, -31521, 6270, -17855, 17855, 6270, -31521, -17855, 6270, 26722, 26722, -31521};
-static __align16(const int16_t, M128_tab_i_26[]) = {21407, 27969, 21407, 11585, 21407, -11585, 21407, -27969, 21407, 11585, -21407, -27969, -21407, 27969, 21407, -11585, 29692, 25172, 25172, -5906, 16819, -29692, 5906, -16819, 16819, 5906, -29692, -16819, 5906, 25172, 25172, -29692};
-static __align16(const int16_t, M128_tab_i_35[]) = {19266, 25172, 19266, 10426, 19266, -10426, 19266, -25172, 19266, 10426, -19266, -25172, -19266, 25172, 19266, -10426, 26722, 22654, 22654, -5315, 15137, -26722, 5315, -15137, 15137, 5315, -26722, -15137, 5315, 22654, 22654, -26722};
-
-static __forceinline void DCT_8_INV_ROW(const uint8_t* const ecx, const uint8_t* const esi, __m128i& xmm0, __m128i& xmm1, __m128i& xmm2, __m128i& xmm3, __m128i& xmm4, __m128i& xmm5, __m128i& xmm6, __m128i& xmm7)
-{
- xmm0 = _mm_shufflelo_epi16(xmm0, 0xD8);
- xmm1 = _mm_shuffle_epi32(xmm0, 0);
- pmaddwd(xmm1, esi);
- xmm3 = _mm_shuffle_epi32(xmm0, 0x55);
- xmm0 = _mm_shufflehi_epi16(xmm0, 0xD8);
- pmaddwd(xmm3, esi + 32);
- xmm2 = _mm_shuffle_epi32(xmm0, 0xAA);
- xmm0 = _mm_shuffle_epi32(xmm0, 0xFF);
- pmaddwd(xmm2, esi + 16);
- xmm4 = _mm_shufflehi_epi16(xmm4, 0xD8);
- paddd(xmm1, M128_round_inv_row);
- xmm4 = _mm_shufflelo_epi16(xmm4, 0xD8);
- pmaddwd(xmm0, esi + 48);
- xmm5 = _mm_shuffle_epi32(xmm4, 0);
- xmm6 = _mm_shuffle_epi32(xmm4, 0xAA);
- pmaddwd(xmm5, ecx);
- paddd(xmm1, xmm2);
- movdqa(xmm2, xmm1);
- xmm7 = _mm_shuffle_epi32(xmm4, 0x55);
- pmaddwd(xmm6, ecx + 16);
- paddd(xmm0, xmm3);
- xmm4 = _mm_shuffle_epi32(xmm4, 0xFF);
- psubd(xmm2, xmm0);
- pmaddwd(xmm7, ecx + 32);
- paddd(xmm0, xmm1);
- psrad(xmm2, 12);
- paddd(xmm5, M128_round_inv_row);
- pmaddwd(xmm4, ecx + 48);
- paddd(xmm5, xmm6);
- movdqa(xmm6, xmm5);
- psrad(xmm0, 12);
- xmm2 = _mm_shuffle_epi32(xmm2, 0x1B);
- packssdw(xmm0, xmm2);
- paddd(xmm4, xmm7);
- psubd(xmm6, xmm4);
- paddd(xmm4, xmm5);
- psrad(xmm6, 12);
- psrad(xmm4, 12);
- xmm6 = _mm_shuffle_epi32(xmm6, 0x1B);
- packssdw(xmm4, xmm6);
-}
-static __forceinline void DCT_8_INV_COL_8(__m128i& src0, __m128i& src1, __m128i& src2, __m128i& src3, __m128i& src4, __m128i& src5, __m128i& src6, __m128i& src7,
- __m128i& xmm0, __m128i& xmm1, __m128i& xmm2, __m128i& xmm3, __m128i& xmm4, __m128i& xmm5, __m128i& xmm6, __m128i& xmm7)
-{
- movdqa(xmm1, M128_tg_3_16);
- movdqa(xmm2, xmm0);
- movdqa(xmm3, src3);
- pmulhw(xmm0, xmm1);
- pmulhw(xmm1, xmm3);
- movdqa(xmm5, M128_tg_1_16);
- movdqa(xmm6, xmm4);
- pmulhw(xmm4, xmm5);
- paddsw(xmm0, xmm2);
- pmulhw(xmm5, src1);
- paddsw(xmm1, xmm3);
- movdqa(xmm7, src6);
- paddsw(xmm0, xmm3);
- movdqa(xmm3, M128_tg_2_16);
- psubsw(xmm2, xmm1);
- pmulhw(xmm7, xmm3);
- movdqa(xmm1, xmm0);
- pmulhw(xmm3, src2);
- psubsw(xmm5, xmm6);
- paddsw(xmm4, src1);
- paddsw(xmm0, xmm4);
- paddsw(xmm0, M128_one_corr);
- psubsw(xmm4, xmm1);
- movdqa(xmm6, xmm5);
- psubsw(xmm5, xmm2);
- paddsw(xmm5, M128_one_corr);
- paddsw(xmm6, xmm2);
- movdqa(src7, xmm0);
- movdqa(xmm1, xmm4);
- movdqa(xmm0, M128_cos_4_16);
- paddsw(xmm4, xmm5);
- movdqa(xmm2, M128_cos_4_16);
- pmulhw(xmm2, xmm4);
- movdqa(src3, xmm6);
- psubsw(xmm1, xmm5);
- paddsw(xmm7, src2);
- psubsw(xmm3, src6);
- movdqa(xmm6, src0);
- pmulhw(xmm0, xmm1);
- movdqa(xmm5, src4);
- paddsw(xmm5, xmm6);
- psubsw(xmm6, src4);
- paddsw(xmm4, xmm2);
- por(xmm4, M128_one_corr);
- paddsw(xmm0, xmm1);
- por(xmm0, M128_one_corr);
- movdqa(xmm2, xmm5);
- paddsw(xmm5, xmm7);
- movdqa(xmm1, xmm6);
- paddsw(xmm5, M128_round_inv_col);
- psubsw(xmm2, xmm7);
- movdqa(xmm7, src7);
- paddsw(xmm6, xmm3);
- paddsw(xmm6, M128_round_inv_col);
- paddsw(xmm7, xmm5);
- psraw(xmm7, SHIFT_INV_COL);
- psubsw(xmm1, xmm3);
- paddsw(xmm1, M128_round_inv_corr);
- movdqa(xmm3, xmm6);
- paddsw(xmm2, M128_round_inv_corr);
- paddsw(xmm6, xmm4);
- movdqa(src0, xmm7);
- psraw(xmm6, SHIFT_INV_COL);
- movdqa(xmm7, xmm1);
- paddsw(xmm1, xmm0);
- movdqa(src1, xmm6);
- psraw(xmm1, SHIFT_INV_COL);
- movdqa(xmm6, src3);
- psubsw(xmm7, xmm0);
- psraw(xmm7, SHIFT_INV_COL);
- movdqa(src2, xmm1);
- psubsw(xmm5, src7);
- psraw(xmm5, SHIFT_INV_COL);
- movdqa(src7, xmm5);
- psubsw(xmm3, xmm4);
- paddsw(xmm6, xmm2);
- psubsw(xmm2, src3);
- psraw(xmm6, SHIFT_INV_COL);
- psraw(xmm2, SHIFT_INV_COL);
- movdqa(src3, xmm6);
- psraw(xmm3, SHIFT_INV_COL);
- movdqa(src4, xmm2);
- movdqa(src5, xmm7);
- movdqa(src6, xmm3);
-}
-
-static __forceinline void idct_M128ASM(__m128i& src0, __m128i& src1, __m128i& src2, __m128i& src3, __m128i& src4, __m128i& src5, __m128i& src6, __m128i& src7)
-{
- __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7;
- movdqa(xmm0, src0);
- uint8_t* esi = (uint8_t*)M128_tab_i_04;
- movdqa(xmm4, src2);
- uint8_t* ecx = (uint8_t*)M128_tab_i_26;
- DCT_8_INV_ROW(ecx, esi, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7);
- movdqa(src0, xmm0);
- movdqa(src2, xmm4);
-
- movdqa(xmm0, src4);
- movdqa(xmm4, src6);
- DCT_8_INV_ROW(ecx, esi, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7);
- movdqa(src4, xmm0);
- movdqa(src6, xmm4);
-
- movdqa(xmm0, src3);
- esi = (uint8_t*)M128_tab_i_35;
- movdqa(xmm4, src1);
- ecx = (uint8_t*)M128_tab_i_17;
- DCT_8_INV_ROW(ecx, esi, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7);
- movdqa(src3, xmm0);
- movdqa(src1, xmm4);
-
- movdqa(xmm0, src5);
- movdqa(xmm4, src7);
- DCT_8_INV_ROW(ecx, esi, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7);
- DCT_8_INV_COL_8(src0, src1, src2, src3, src4, src5, src6, src7,
- xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7);
-}
-
-void mpeg2_idct_copy_sse2(int16_t* block, uint8_t* dest, const int stride)
-{
- __m128i& src0 = *(__m128i*)(block + 0 * 16 / 2);
- __m128i& src1 = *(__m128i*)(block + 1 * 16 / 2);
- __m128i& src2 = *(__m128i*)(block + 2 * 16 / 2);
- __m128i& src3 = *(__m128i*)(block + 3 * 16 / 2);
- __m128i& src4 = *(__m128i*)(block + 4 * 16 / 2);
- __m128i& src5 = *(__m128i*)(block + 5 * 16 / 2);
- __m128i& src6 = *(__m128i*)(block + 6 * 16 / 2);
- __m128i& src7 = *(__m128i*)(block + 7 * 16 / 2);
- idct_M128ASM(src0, src1, src2, src3, src4, src5, src6, src7);
-
- __m128i zero = _mm_setzero_si128();
-
- __m128i r0 = _mm_packus_epi16(_mm_load_si128(&src0), _mm_load_si128(&src1));
- __m128i r1 = _mm_packus_epi16(_mm_load_si128(&src2), _mm_load_si128(&src3));
- __m128i r2 = _mm_packus_epi16(_mm_load_si128(&src4), _mm_load_si128(&src5));
- __m128i r3 = _mm_packus_epi16(_mm_load_si128(&src6), _mm_load_si128(&src7));
-
- _mm_storel_pi((__m64*)&dest[0 * stride], *(__m128*)&r0);
- _mm_storeh_pi((__m64*)&dest[1 * stride], *(__m128*)&r0);
- _mm_storel_pi((__m64*)&dest[2 * stride], *(__m128*)&r1);
- _mm_storeh_pi((__m64*)&dest[3 * stride], *(__m128*)&r1);
- _mm_storel_pi((__m64*)&dest[4 * stride], *(__m128*)&r2);
- _mm_storeh_pi((__m64*)&dest[5 * stride], *(__m128*)&r2);
- _mm_storel_pi((__m64*)&dest[6 * stride], *(__m128*)&r3);
- _mm_storeh_pi((__m64*)&dest[7 * stride], *(__m128*)&r3);
-
- _mm_store_si128(&src0, zero);
- _mm_store_si128(&src1, zero);
- _mm_store_si128(&src2, zero);
- _mm_store_si128(&src3, zero);
- _mm_store_si128(&src4, zero);
- _mm_store_si128(&src5, zero);
- _mm_store_si128(&src6, zero);
- _mm_store_si128(&src7, zero);
-}
-
-void mpeg2_idct_add_sse2(int, int16_t* block, uint8_t* dest, const int stride)
-{
- __m128i& src0 = *(__m128i*)(block + 0 * 16 / 2);
- __m128i& src1 = *(__m128i*)(block + 1 * 16 / 2);
- __m128i& src2 = *(__m128i*)(block + 2 * 16 / 2);
- __m128i& src3 = *(__m128i*)(block + 3 * 16 / 2);
- __m128i& src4 = *(__m128i*)(block + 4 * 16 / 2);
- __m128i& src5 = *(__m128i*)(block + 5 * 16 / 2);
- __m128i& src6 = *(__m128i*)(block + 6 * 16 / 2);
- __m128i& src7 = *(__m128i*)(block + 7 * 16 / 2);
- idct_M128ASM(src0, src1, src2, src3, src4, src5, src6, src7);
-
- __m128i zero = _mm_setzero_si128();
-
- __m128i r0 = _mm_load_si128(&src0);
- __m128i r1 = _mm_load_si128(&src1);
- __m128i r2 = _mm_load_si128(&src2);
- __m128i r3 = _mm_load_si128(&src3);
- __m128i r4 = _mm_load_si128(&src4);
- __m128i r5 = _mm_load_si128(&src5);
- __m128i r6 = _mm_load_si128(&src6);
- __m128i r7 = _mm_load_si128(&src7);
-
- __m128 q0 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[0 * stride]);
- __m128 q1 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[1 * stride]);
- __m128 q2 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[2 * stride]);
- __m128 q3 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[3 * stride]);
- __m128 q4 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[4 * stride]);
- __m128 q5 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[5 * stride]);
- __m128 q6 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[6 * stride]);
- __m128 q7 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[7 * stride]);
-
- r0 = _mm_adds_epi16(r0, _mm_unpacklo_epi8(*(__m128i*)&q0, zero));
- r1 = _mm_adds_epi16(r1, _mm_unpacklo_epi8(*(__m128i*)&q1, zero));
- r2 = _mm_adds_epi16(r2, _mm_unpacklo_epi8(*(__m128i*)&q2, zero));
- r3 = _mm_adds_epi16(r3, _mm_unpacklo_epi8(*(__m128i*)&q3, zero));
- r4 = _mm_adds_epi16(r4, _mm_unpacklo_epi8(*(__m128i*)&q4, zero));
- r5 = _mm_adds_epi16(r5, _mm_unpacklo_epi8(*(__m128i*)&q5, zero));
- r6 = _mm_adds_epi16(r6, _mm_unpacklo_epi8(*(__m128i*)&q6, zero));
- r7 = _mm_adds_epi16(r7, _mm_unpacklo_epi8(*(__m128i*)&q7, zero));
-
- r0 = _mm_packus_epi16(r0, r1);
- r1 = _mm_packus_epi16(r2, r3);
- r2 = _mm_packus_epi16(r4, r5);
- r3 = _mm_packus_epi16(r6, r7);
-
- _mm_storel_pi((__m64*)&dest[0 * stride], *(__m128*)&r0);
- _mm_storeh_pi((__m64*)&dest[1 * stride], *(__m128*)&r0);
- _mm_storel_pi((__m64*)&dest[2 * stride], *(__m128*)&r1);
- _mm_storeh_pi((__m64*)&dest[3 * stride], *(__m128*)&r1);
- _mm_storel_pi((__m64*)&dest[4 * stride], *(__m128*)&r2);
- _mm_storeh_pi((__m64*)&dest[5 * stride], *(__m128*)&r2);
- _mm_storel_pi((__m64*)&dest[6 * stride], *(__m128*)&r3);
- _mm_storeh_pi((__m64*)&dest[7 * stride], *(__m128*)&r3);
-
- _mm_store_si128(&src0, zero);
- _mm_store_si128(&src1, zero);
- _mm_store_si128(&src2, zero);
- _mm_store_si128(&src3, zero);
- _mm_store_si128(&src4, zero);
- _mm_store_si128(&src5, zero);
- _mm_store_si128(&src6, zero);
- _mm_store_si128(&src7, zero);
-}
-
-void mpeg2_idct_init_sse2()
-{
-}
diff --git a/src/filters/transform/Mpeg2DecFilter/libmpeg2.cpp b/src/filters/transform/Mpeg2DecFilter/libmpeg2.cpp
deleted file mode 100644
index 10e9abd98..000000000
--- a/src/filters/transform/Mpeg2DecFilter/libmpeg2.cpp
+++ /dev/null
@@ -1,3743 +0,0 @@
-/*
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
- * See http://libmpeg2.sourceforge.net/ for updates.
- *
- * mpeg2dec 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 of the License, or
- * (at your option) any later version.
- *
- * mpeg2dec 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "stdafx.h"
-#include <stdlib.h>
-#include <string.h>
-#include <malloc.h>
-#include "libmpeg2.h"
-#include "../../../DSUtil/vd.h"
-
-#ifdef _WIN64
-#pragma warning(push)
-#pragma warning(disable:4244)
-#endif
-
-// decode
-
-#define SEQ_EXT 2
-#define SEQ_DISPLAY_EXT 4
-#define QUANT_MATRIX_EXT 8
-#define COPYRIGHT_EXT 0x10
-#define PIC_DISPLAY_EXT 0x80
-#define PIC_CODING_EXT 0x100
-
-/* default intra quant matrix, in zig-zag order */
-static const uint8_t default_intra_quantizer_matrix[64] = {
- 8,
- 16, 16,
- 19, 16, 19,
- 22, 22, 22, 22,
- 22, 22, 26, 24, 26,
- 27, 27, 27, 26, 26, 26,
- 26, 27, 27, 27, 29, 29, 29,
- 34, 34, 34, 29, 29, 29, 27, 27,
- 29, 29, 32, 32, 34, 34, 37,
- 38, 37, 35, 35, 34, 35,
- 38, 38, 40, 40, 40,
- 48, 48, 46, 46,
- 56, 56, 58,
- 69, 69,
- 83
-};
-
-static uint8_t mpeg2_scan_norm_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
-};
-
-static uint8_t mpeg2_scan_alt_2[64] = {
- /* 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
-};
-
-// dummy
-extern "C" uint8_t mpeg2_scan_norm[64];
-extern "C" uint8_t mpeg2_scan_alt[64];
-uint8_t mpeg2_scan_norm[64];
-uint8_t mpeg2_scan_alt[64];
-
-// idct (c)
-
-#define W1 2841 /* 2048 * sqrt (2) * cos (1 * pi / 16) */
-#define W2 2676 /* 2048 * sqrt (2) * cos (2 * pi / 16) */
-#define W3 2408 /* 2048 * sqrt (2) * cos (3 * pi / 16) */
-#define W5 1609 /* 2048 * sqrt (2) * cos (5 * pi / 16) */
-#define W6 1108 /* 2048 * sqrt (2) * cos (6 * pi / 16) */
-#define W7 565 /* 2048 * sqrt (2) * cos (7 * pi / 16) */
-
-/*
- * In legal streams, the IDCT output should be between -384 and +384.
- * In corrupted streams, it is possible to force the IDCT output to go
- * to +-3826 - this is the worst case for a column IDCT where the
- * column inputs are 16-bit values.
- */
-static uint8_t mpeg2_clip[3840 * 2 + 256];
-#define CLIP(i) ((mpeg2_clip + 3840)[i])
-
-#define BUTTERFLY(t0,t1,W0,W1,d0,d1) \
-{ \
- int tmp = W0 * (d0 + d1); \
- t0 = tmp + (W1 - W0) * d1; \
- t1 = tmp - (W1 + W0) * d0; \
-}
-
-static void __inline idct_row(int16_t* block)
-{
- int d0, d1, d2, d3;
- int a0, a1, a2, a3, b0, b1, b2, b3;
- int t0, t1, t2, t3;
-
- /* shortcut */
- if(!(block[1] | ((int32_t *)block)[1] | ((int32_t *)block)[2] | ((int32_t *)block)[3]))
- {
- uint32_t tmp = (uint16_t) (block[0] << 3);
- tmp |= tmp << 16;
- ((int32_t *)block)[0] = tmp;
- ((int32_t *)block)[1] = tmp;
- ((int32_t *)block)[2] = tmp;
- ((int32_t *)block)[3] = tmp;
- return;
- }
-
- d0 = (block[0] << 11) + 128;
- d1 = block[1];
- d2 = block[2] << 11;
- d3 = block[3];
- t0 = d0 + d2;
- t1 = d0 - d2;
- BUTTERFLY(t2, t3, W6, W2, d3, d1);
- a0 = t0 + t2;
- a1 = t1 + t3;
- a2 = t1 - t3;
- a3 = t0 - t2;
-
- d0 = block[4];
- d1 = block[5];
- d2 = block[6];
- d3 = block[7];
- BUTTERFLY(t0, t1, W7, W1, d3, d0);
- BUTTERFLY(t2, t3, W3, W5, d1, d2);
- b0 = t0 + t2;
- b3 = t1 + t3;
- t0 -= t2;
- t1 -= t3;
- b1 = ((t0 + t1) * 181) >> 8;
- b2 = ((t0 - t1) * 181) >> 8;
-
- block[0] = (a0 + b0) >> 8;
- block[1] = (a1 + b1) >> 8;
- block[2] = (a2 + b2) >> 8;
- block[3] = (a3 + b3) >> 8;
- block[4] = (a3 - b3) >> 8;
- block[5] = (a2 - b2) >> 8;
- block[6] = (a1 - b1) >> 8;
- block[7] = (a0 - b0) >> 8;
-}
-
-static void __inline idct_col(int16_t* block)
-{
- int d0, d1, d2, d3;
- int a0, a1, a2, a3, b0, b1, b2, b3;
- int t0, t1, t2, t3;
-
- d0 = (block[8*0] << 11) + 65536;
- d1 = block[8*1];
- d2 = block[8*2] << 11;
- d3 = block[8*3];
- t0 = d0 + d2;
- t1 = d0 - d2;
- BUTTERFLY(t2, t3, W6, W2, d3, d1);
- a0 = t0 + t2;
- a1 = t1 + t3;
- a2 = t1 - t3;
- a3 = t0 - t2;
-
- d0 = block[8*4];
- d1 = block[8*5];
- d2 = block[8*6];
- d3 = block[8*7];
- BUTTERFLY(t0, t1, W7, W1, d3, d0);
- BUTTERFLY(t2, t3, W3, W5, d1, d2);
- b0 = t0 + t2;
- b3 = t1 + t3;
- t0 = (t0 - t2) >> 8;
- t1 = (t1 - t3) >> 8;
- b1 = (t0 + t1) * 181;
- b2 = (t0 - t1) * 181;
-
- block[8*0] = (a0 + b0) >> 17;
- block[8*1] = (a1 + b1) >> 17;
- block[8*2] = (a2 + b2) >> 17;
- block[8*3] = (a3 + b3) >> 17;
- block[8*4] = (a3 - b3) >> 17;
- block[8*5] = (a2 - b2) >> 17;
- block[8*6] = (a1 - b1) >> 17;
- block[8*7] = (a0 - b0) >> 17;
-}
-
-static void mpeg2_idct_copy_c(int16_t* block, uint8_t* dest, const int stride)
-{
- for(int i = 0; i < 8; i++) idct_row(block + 8 * i);
- for(int i = 0; i < 8; i++) idct_col(block + i);
- for(int i = 0; i < 8; i++)
- {
- dest[0] = CLIP(block[0]);
- dest[1] = CLIP(block[1]);
- dest[2] = CLIP(block[2]);
- dest[3] = CLIP(block[3]);
- dest[4] = CLIP(block[4]);
- dest[5] = CLIP(block[5]);
- dest[6] = CLIP(block[6]);
- dest[7] = CLIP(block[7]);
-
- block[0] = 0; block[1] = 0; block[2] = 0; block[3] = 0;
- block[4] = 0; block[5] = 0; block[6] = 0; block[7] = 0;
-
- dest += stride;
- block += 8;
- }
-}
-
-static void mpeg2_idct_add_c(const int last, int16_t* block, uint8_t* dest, const int stride)
-{
- if(last != 129 || (block[0] & 7) == 4)
- {
- for(int i = 0; i < 8; i++) idct_row(block + 8 * i);
- for(int i = 0; i < 8; i++) idct_col(block + i);
- for(int i = 0; i < 8; i++)
- {
- dest[0] = CLIP(block[0] + dest[0]);
- dest[1] = CLIP(block[1] + dest[1]);
- dest[2] = CLIP(block[2] + dest[2]);
- dest[3] = CLIP(block[3] + dest[3]);
- dest[4] = CLIP(block[4] + dest[4]);
- dest[5] = CLIP(block[5] + dest[5]);
- dest[6] = CLIP(block[6] + dest[6]);
- dest[7] = CLIP(block[7] + dest[7]);
-
- block[0] = 0; block[1] = 0; block[2] = 0; block[3] = 0;
- block[4] = 0; block[5] = 0; block[6] = 0; block[7] = 0;
-
- dest += stride;
- block += 8;
- }
- }
- else
- {
- int DC = (block[0] + 4) >> 3;
- block[0] = block[63] = 0;
- for(int i = 0; i < 8; i++)
- {
- dest[0] = CLIP(DC + dest[0]);
- dest[1] = CLIP(DC + dest[1]);
- dest[2] = CLIP(DC + dest[2]);
- dest[3] = CLIP(DC + dest[3]);
- dest[4] = CLIP(DC + dest[4]);
- dest[5] = CLIP(DC + dest[5]);
- dest[6] = CLIP(DC + dest[6]);
- dest[7] = CLIP(DC + dest[7]);
- dest += stride;
- }
- }
-}
-
-static void mpeg2_idct_init_c()
-{
- for(int i = -3840; i < 3840 + 256; i++)
- {
- CLIP(i) = (i < 0) ? 0 : ((i > 255) ? 255 : i);
- }
-
- // only needed with idct_c
-
- for(int i = 0; i < 64; i++)
- {
- mpeg2_scan_norm_2[i] = ((mpeg2_scan_norm_2[i] & 0x36) >> 1) | ((mpeg2_scan_norm_2[i] & 0x09) << 2);
- mpeg2_scan_alt_2[i] = ((mpeg2_scan_alt_2[i] & 0x36) >> 1) | ((mpeg2_scan_alt_2[i] & 0x09) << 2);
- }
-}
-
-// mc (c)
-
-#define avg2(a,b) ((a+b+1)>>1)
-#define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
-
-#define predict_o(i) (ref[i])
-#define predict_x(i) (avg2(ref[i], ref[i+1]))
-#define predict_y(i) (avg2(ref[i], (ref+stride)[i]))
-#define predict_xy(i) (avg4(ref[i], ref[i+1], (ref+stride)[i], (ref+stride)[i+1]))
-
-#define put(predictor,i) dest[i] = predictor(i)
-#define avg(predictor,i) dest[i] = avg2(predictor(i), dest[i])
-
-/* mc function template */
-
-#define MC_FUNC(op,xy) \
-static void MC_##op##_##xy##_16_c (uint8_t* dest, const uint8_t* ref, const int stride, int height) \
-{ \
- do { \
- op (predict_##xy, 0); \
- op (predict_##xy, 1); \
- op (predict_##xy, 2); \
- op (predict_##xy, 3); \
- op (predict_##xy, 4); \
- op (predict_##xy, 5); \
- op (predict_##xy, 6); \
- op (predict_##xy, 7); \
- op (predict_##xy, 8); \
- op (predict_##xy, 9); \
- op (predict_##xy, 10); \
- op (predict_##xy, 11); \
- op (predict_##xy, 12); \
- op (predict_##xy, 13); \
- op (predict_##xy, 14); \
- op (predict_##xy, 15); \
- ref += stride; \
- dest += stride; \
- } while (--height); \
-} \
-static void MC_##op##_##xy##_8_c (uint8_t * dest, const uint8_t * ref, const int stride, int height) \
-{ \
- do { \
- op (predict_##xy, 0); \
- op (predict_##xy, 1); \
- op (predict_##xy, 2); \
- op (predict_##xy, 3); \
- op (predict_##xy, 4); \
- op (predict_##xy, 5); \
- op (predict_##xy, 6); \
- op (predict_##xy, 7); \
- ref += stride; \
- dest += stride; \
- } while (--height); \
-}
-
-/* definitions of the actual mc functions */
-
-MC_FUNC(put,o)
-MC_FUNC(avg,o)
-MC_FUNC(put,x)
-MC_FUNC(avg,x)
-MC_FUNC(put,y)
-MC_FUNC(avg,y)
-MC_FUNC(put,xy)
-MC_FUNC(avg,xy)
-
-#define MPEG2_MC_EXTERN(x) mpeg2_mc_t mpeg2_mc_##x = { \
- {MC_put_o_16_##x, MC_put_x_16_##x, MC_put_y_16_##x, MC_put_xy_16_##x, \
- MC_put_o_8_##x, MC_put_x_8_##x, MC_put_y_8_##x, MC_put_xy_8_##x}, \
- {MC_avg_o_16_##x, MC_avg_x_16_##x, MC_avg_y_16_##x, MC_avg_xy_16_##x, \
- MC_avg_o_8_##x, MC_avg_x_8_##x, MC_avg_y_8_##x, MC_avg_xy_8_##x} \
-};
-
-MPEG2_MC_EXTERN(c)
-
-// idct (mmx)
-
-extern "C" void mpeg2_idct_copy_mmx(int16_t* block, uint8_t* dest, const int stride);
-extern "C" void mpeg2_idct_add_mmx(const int last, int16_t* block, uint8_t* dest, const int stride);
-
-static void mpeg2_idct_init_mmx()
-{
- for(int i = 0; i < 64; i++)
- {
- mpeg2_scan_norm_2[i] = (mpeg2_scan_norm_2[i] & 0x38) | ((mpeg2_scan_norm_2[i] & 6) >> 1) | ((mpeg2_scan_norm_2[i] & 1) << 2);
- mpeg2_scan_alt_2[i] = (mpeg2_scan_alt_2[i] & 0x38) | ((mpeg2_scan_alt_2[i] & 6) >> 1) | ((mpeg2_scan_alt_2[i] & 1) << 2);
- }
-}
-
-// mc (mmx)
-
-extern "C" mpeg2_mc_t mpeg2_mc_mmx;
-
-// idct (sse2)
-
-extern void mpeg2_idct_init_sse2();
-extern void mpeg2_idct_copy_sse2(int16_t* block, uint8_t* dest, const int stride);
-extern void mpeg2_idct_add_sse2(const int last, int16_t* block, uint8_t* dest, const int stride);
-
-// mc (sse2)
-
-extern mpeg2_mc_t mpeg2_mc_sse2;
-
-// idct (c)
-
-static void mpeg2_idct_init_c();
-static void mpeg2_idct_copy_c(int16_t* block, uint8_t* dest, const int stride);
-static void mpeg2_idct_add_c(const int last, int16_t* block, uint8_t* dest, const int stride);
-
- // mc (c)
-
-static void MC_c(uint8_t* dest, const uint8_t* ref, const int stride, int height);
-
-extern mpeg2_mc_t mpeg2_mc_c;
-
-//
-
-CMpeg2Dec::CMpeg2Dec()
-{
- m_shift = 0;
- m_is_display_initialized = 0;
- m_action = NULL;
- m_state = STATE_BUFFER;
- m_ext_state = 0;
-
- m_chunk_buffer = m_chunk_start = m_chunk_ptr = NULL;
- m_code = 0;
-
- m_pts_current = m_pts_previous = 0;
- m_num_pts = m_bytes_since_pts = 0;
-
- m_first = 0;
- m_alloc_index = 0;
- m_first_decode_slice = m_nb_decode_slices = 0;
-
- memset(&m_new_sequence, 0, sizeof(m_new_sequence));
- memset(&m_sequence, 0, sizeof(m_sequence));
- memset(&m_gop, 0, sizeof(m_gop));
- memset(&m_pictures, 0, sizeof(m_pictures));
- m_picture = NULL;
- memset(&m_fbuf, 0, sizeof(m_fbuf));
- memset(&m_fbuf_alloc, 0, sizeof(m_fbuf_alloc));
-
- m_buf_start = m_buf_end = NULL;
-
- m_display_offset_x = m_display_offset_y = 0;
-
- m_copy_matrix = 0;
- memset(&m_intra_quantizer_matrix, 0, sizeof(m_intra_quantizer_matrix));
- memset(&m_non_intra_quantizer_matrix, 0, sizeof(m_non_intra_quantizer_matrix));
-
- //
-
- mpeg2_init();
-}
-
-CMpeg2Dec::~CMpeg2Dec()
-{
- mpeg2_close();
-}
-
-void CMpeg2Dec::mpeg2_init()
-{
- m_chunk_buffer = (uint8_t*)_aligned_malloc(BUFFER_SIZE + 4, 16);
- m_shift = 0xffffff00;
- m_code = 0xb4;
- m_action = &CMpeg2Dec::mpeg2_seek_sequence;
- m_sequence.width = (unsigned)-1;
-}
-
-void CMpeg2Dec::mpeg2_close()
-{
- /* static uint8_t finalizer[] = {0,0,1,0xb4}; */
- /* mpeg2_decode_data (mpeg2dec, finalizer, finalizer+4); */
-
- mpeg2_header_state_init();
- _aligned_free(m_chunk_buffer);
-}
-
-//
-
-int CMpeg2Dec::skip_chunk(int bytes)
-{
- if(!bytes)
- return 0;
-
- int len = 0;
-
- uint8_t* current = m_buf_start;
- uint8_t* limit = current + bytes;
-
- while(current < limit)
- {
- if(m_shift == 0x00000100)
- {
- m_shift = 0xffffff00;
- len = ++current - m_buf_start;
- break;
- }
-
- m_shift = (m_shift | *current++) << 8;
- }
-
- m_buf_start = current;
-
- return len;
-}
-
-int CMpeg2Dec::copy_chunk(int bytes)
-{
- if(!bytes)
- return 0;
-
- int len = 0;
-
- // this assembly gives us a nice speed up
- // 36 sec down to 32 sec decoding the ts.stream.tpr test file
- // (idtc, mc was set to null)
-#ifndef _WIN64
- __asm
- {
- mov ebx, this
- mov esi, [ebx].m_buf_start
- mov edi, [ebx].m_chunk_ptr
- mov ecx, bytes
- mov edx, [ebx].m_shift
-
- copy_chunk_loop:
-
- cmp edx, 0x00000100
- jne copy_chunk_continue
- mov edx, 0xffffff00
-
- inc edi
- mov [ebx].m_chunk_ptr, edi
-
- inc esi
- mov eax, esi
- sub eax, [ebx].m_buf_start
- mov len, eax
-
- jmp copy_chunk_end
-
- copy_chunk_continue:
-
- movzx eax, byte ptr [esi]
- or edx, eax
- shl edx, 8
- mov byte ptr [edi], al
- inc esi
- inc edi
- dec ecx
- jnz copy_chunk_loop
-
- copy_chunk_end:
-
- mov [ebx].m_buf_start, esi
- mov [ebx].m_shift, edx
- }
-#else
- uint8_t* chunk_ptr = m_chunk_ptr;
- uint8_t* current = m_buf_start;
- uint8_t* limit = current + bytes;
-
- while(current < limit)
- {
- if(m_shift == 0x00000100)
- {
- m_shift = 0xffffff00;
- len = ++current - m_buf_start;
- m_chunk_ptr = ++chunk_ptr;
- break;
- }
-
- m_shift = (m_shift | (*chunk_ptr++ = *current++)) << 8;
- }
-
- m_buf_start = current;
-#endif
- return len;
-}
-
-mpeg2_state_t CMpeg2Dec::seek_chunk()
-{
- int size = m_buf_end - m_buf_start;
-
- if(int skipped = skip_chunk(size))
- {
- m_bytes_since_pts += skipped;
- m_code = m_buf_start[-1];
- return (mpeg2_state_t)-1;
- }
-
- m_bytes_since_pts += size;
- return STATE_BUFFER;
-}
-
-mpeg2_state_t CMpeg2Dec::seek_header()
-{
- while(m_code != 0xb3 && (m_code != 0xb7 && m_code != 0xb8 && m_code || m_sequence.width == (unsigned)-1))
- {
- if(seek_chunk() == STATE_BUFFER)
- return STATE_BUFFER;
- }
-
- m_chunk_start = m_chunk_ptr = m_chunk_buffer;
-
- return m_code
- ? mpeg2_parse_header()
- : mpeg2_header_picture_start();
-}
-
-mpeg2_state_t CMpeg2Dec::seek_sequence()
-{
- mpeg2_header_state_init();
- m_action = &CMpeg2Dec::seek_header;
- return seek_header();
-}
-
-//
-
-void CMpeg2Dec::mpeg2_buffer(uint8_t* start, uint8_t* end)
-{
- m_buf_start = start;
- m_buf_end = end;
-}
-
-int CMpeg2Dec::mpeg2_getpos()
-{
- return m_buf_end - m_buf_start;
-}
-
-//
-
-mpeg2_state_t CMpeg2Dec::mpeg2_parse()
-{
- if(m_action)
- {
- mpeg2_state_t state = (this->*m_action)();
- if((int)state >= 0)
- return state;
- }
-
- while(1)
- {
- while((unsigned)(m_code - m_first_decode_slice) < m_nb_decode_slices)
- {
- int size_buffer = m_buf_end - m_buf_start;
- int size_chunk = (m_chunk_buffer + BUFFER_SIZE - m_chunk_ptr);
- int copied;
-
- if(size_buffer <= size_chunk)
- {
- copied = copy_chunk(size_buffer);
- if(!copied)
- {
- m_bytes_since_pts += size_buffer;
- m_chunk_ptr += size_buffer;
- return STATE_BUFFER;
- }
- }
- else
- {
- copied = copy_chunk(size_chunk);
- if(!copied)
- {
- /* filled the chunk buffer without finding a start code */
- m_bytes_since_pts += size_chunk;
- m_action = &CMpeg2Dec::seek_chunk;
- return STATE_INVALID;
- }
- }
-
- m_bytes_since_pts += copied;
-
- m_decoder.mpeg2_slice(m_code, m_chunk_start);
- m_code = m_buf_start[-1];
- m_chunk_ptr = m_chunk_start;
- }
-
- if((unsigned)(m_code - 1) >= 0xb0 - 1)
- break;
- if(seek_chunk() == STATE_BUFFER)
- return STATE_BUFFER;
- }
-
- switch(m_code)
- {
- case 0x00:
- m_action = &CMpeg2Dec::mpeg2_header_picture_start;
- return m_state;
- case 0xb7:
- m_action = &CMpeg2Dec::mpeg2_header_end;
- break;
- case 0xb3:
- case 0xb8:
- m_action = &CMpeg2Dec::mpeg2_parse_header;
- break;
- case 0xbe:
- m_action = &CMpeg2Dec::seek_chunk;
- return STATE_PADDING;
- default:
- m_action = &CMpeg2Dec::seek_chunk;
- return STATE_INVALID;
- }
-
- if(m_state != STATE_SLICE)
- m_state = STATE_INVALID;
-
- return m_state;
-}
-
-
-void CMpeg2Dec::mpeg2_skip(int skip)
-{
- m_first_decode_slice = 1;
- m_nb_decode_slices = skip ? 0 : (0xb0 - 1);
-}
-
-void CMpeg2Dec::mpeg2_slice_region(int start, int end)
-{
- start = (start < 1) ? 1 : (start > 0xb0) ? 0xb0 : start;
- end = (end < start) ? start : (end > 0xb0) ? 0xb0 : end;
- m_first_decode_slice = start;
- m_nb_decode_slices = end - start;
-}
-
-void CMpeg2Dec::mpeg2_pts(uint32_t pts)
-{
- m_pts_previous = m_pts_current;
- m_pts_current = pts;
- m_num_pts++;
- m_bytes_since_pts = 0;
-}
-
-//
-
-/* decode.c */
-
-#define RECEIVED(code,state) (((state) << 8) + (code))
-
-mpeg2_state_t CMpeg2Dec::mpeg2_seek_sequence()
-{
- mpeg2_header_state_init();
- m_action = &CMpeg2Dec::seek_header;
- return seek_header();
-}
-
-mpeg2_state_t CMpeg2Dec::mpeg2_parse_header()
-{
- static int (CMpeg2Dec::* process_header[]) () =
- {
- &CMpeg2Dec::mpeg2_header_picture,
- &CMpeg2Dec::mpeg2_header_extension,
- &CMpeg2Dec::mpeg2_header_user_data,
- &CMpeg2Dec::mpeg2_header_sequence,
- NULL, NULL, NULL, NULL,
- &CMpeg2Dec::mpeg2_header_gop
- };
-
- m_action = &CMpeg2Dec::mpeg2_parse_header;
-
- while(1)
- {
- int size_buffer = m_buf_end - m_buf_start;
- int size_chunk = (m_chunk_buffer + BUFFER_SIZE - m_chunk_ptr);
- int copied;
- if(size_buffer <= size_chunk)
- {
- copied = copy_chunk(size_buffer);
- if(!copied)
- {
- m_bytes_since_pts += size_buffer;
- m_chunk_ptr += size_buffer;
- return STATE_BUFFER;
- }
- }
- else
- {
- copied = copy_chunk(size_chunk);
- if(!copied)
- {
- /* filled the chunk buffer without finding a start code */
- m_bytes_since_pts += size_chunk;
- m_code = 0xb4;
- m_action = &CMpeg2Dec::seek_header;
- return STATE_INVALID;
- }
- }
- m_bytes_since_pts += copied;
-
- if((this->*(process_header[m_code & 0x0b]))())
- {
- m_code = m_buf_start[-1];
- m_action = &CMpeg2Dec::seek_header;
- return STATE_INVALID;
- }
-
- m_code = m_buf_start[-1];
-
- switch(RECEIVED(m_code, m_state))
- {
- /* state transition after a sequence header */
- case RECEIVED(0x00, STATE_SEQUENCE):
- m_action = &CMpeg2Dec::mpeg2_header_picture_start;
- case RECEIVED(0xb8, STATE_SEQUENCE):
- mpeg2_header_sequence_finalize();
- break;
-
- /* other legal state transitions */
- case RECEIVED (0x00, STATE_GOP):
- m_action = &CMpeg2Dec::mpeg2_header_picture_start;
- break;
- case RECEIVED (0x01, STATE_PICTURE):
- case RECEIVED (0x01, STATE_PICTURE_2ND):
- mpeg2_header_matrix_finalize();
- m_action = &CMpeg2Dec::mpeg2_header_slice_start;
- break;
-
- /* legal headers within a given state */
- case RECEIVED (0xb2, STATE_SEQUENCE):
- case RECEIVED (0xb2, STATE_GOP):
- case RECEIVED (0xb2, STATE_PICTURE):
- case RECEIVED (0xb2, STATE_PICTURE_2ND):
- case RECEIVED (0xb5, STATE_SEQUENCE):
- case RECEIVED (0xb5, STATE_PICTURE):
- case RECEIVED (0xb5, STATE_PICTURE_2ND):
- m_chunk_ptr = m_chunk_start;
- continue;
-
- default:
- m_action = &CMpeg2Dec::seek_header;
- return STATE_INVALID;
- }
-
- m_chunk_start = m_chunk_ptr = m_chunk_buffer;
- return m_state;
- }
-}
-
-/* header.c */
-
-void CMpeg2Dec::mpeg2_header_state_init()
-{
- if(m_sequence.width != (unsigned)-1)
- {
- m_sequence.width = (unsigned)-1;
- for(int i = 0; i < m_alloc_index; i++)
- _aligned_free(m_fbuf_alloc[i].buf[0]);
- }
-
- m_decoder.m_scan = mpeg2_scan_norm_2;
- m_picture = m_pictures;
- m_fbuf[0] = &m_fbuf_alloc[0];
- m_fbuf[1] = &m_fbuf_alloc[1];
- m_fbuf[2] = &m_fbuf_alloc[2];
- m_first = true;
- m_alloc_index = 0;
- m_first_decode_slice = 1;
- m_nb_decode_slices = 0xb0 - 1;
-}
-
-int CMpeg2Dec::mpeg2_header_sequence()
-{
- uint8_t* buffer = m_chunk_start;
- mpeg2_sequence_t* sequence = &m_new_sequence;
- static unsigned int frame_period[9] = {0, 1126125, 1125000, 1080000, 900900, 900000, 540000, 450450, 450000};
-
- if((buffer[6] & 0x20) != 0x20) /* missing marker_bit */
- return 1;
-
- int i = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
- sequence->display_width = sequence->picture_width = i >> 12;
- if(!sequence->display_width)
- return 1;
- sequence->display_height = sequence->picture_height = i & 0xfff;
- if(!sequence->display_height)
- return 1;
-
- sequence->width = (sequence->picture_width + 15) & ~15;
- sequence->height = (sequence->picture_height + 15) & ~15;
- sequence->chroma_width = sequence->width >> 1;
- sequence->chroma_height = sequence->height >> 1;
- sequence->flags = (SEQ_FLAG_PROGRESSIVE_SEQUENCE | SEQ_VIDEO_FORMAT_UNSPECIFIED);
- sequence->pixel_width = buffer[3] >> 4; /* aspect ratio */
- sequence->frame_period = 0;
- if((buffer[3] & 15) < 9) sequence->frame_period = frame_period[buffer[3] & 15];
- sequence->byte_rate = (buffer[4]<<10) | (buffer[5]<<2) | (buffer[6]>>6);
- sequence->vbv_buffer_size = ((buffer[6]<<16)|(buffer[7]<<8))&0x1ff800;
- if(buffer[7] & 4) sequence->flags |= SEQ_FLAG_CONSTRAINED_PARAMETERS;
-
- m_copy_matrix = 3;
- if(buffer[7] & 2)
- {
- for(i = 0; i < 64; i++)
- m_intra_quantizer_matrix[mpeg2_scan_norm_2[i]] = (buffer[i+7] << 7) | (buffer[i+8] >> 1);
- buffer += 64;
- }
- else
- {
- for (i = 0; i < 64; i++)
- m_intra_quantizer_matrix[mpeg2_scan_norm_2[i]] = default_intra_quantizer_matrix[i];
- }
-
- if(buffer[7] & 1)
- {
- for(i = 0; i < 64; i++)
- m_non_intra_quantizer_matrix[mpeg2_scan_norm_2[i]] = buffer[i+8];
- }
- else
- {
- for(i = 0; i < 64; i++)
- m_non_intra_quantizer_matrix[i] = 16;
- }
-
- sequence->profile_level_id = 0x80;
- sequence->colour_primaries = 0;
- sequence->transfer_characteristics = 0;
- sequence->matrix_coefficients = 0;
-
- m_ext_state = SEQ_EXT;
- m_state = STATE_SEQUENCE;
- m_display_offset_x = m_display_offset_y = 0;
-
- m_info.Reset();
- m_info.m_gop = NULL;
-
- return 0;
-}
-
-int CMpeg2Dec::mpeg2_header_gop()
-{
- uint8_t* buffer = m_chunk_start;
- m_info.Reset();
- if(!(buffer[1] & 8))
- return 1;
- m_info.m_gop = &m_gop;
- m_gop.hours = (buffer[0] >> 2) & 31;
- m_gop.minutes = ((buffer[0] << 4) | (buffer[1] >> 4)) & 63;
- m_gop.seconds = ((buffer[1] << 3) | (buffer[2] >> 5)) & 63;
- m_gop.pictures = ((buffer[2] << 1) | (buffer[3] >> 7)) & 63;
- m_gop.flags = (buffer[0] >> 7) | ((buffer[3] >> 4) & 6);
- m_state = STATE_GOP;
- return 0;
-}
-
-mpeg2_state_t CMpeg2Dec::mpeg2_header_picture_start()
-{
- {
- mpeg2_picture_t* picture;
-
- if(m_state != STATE_SLICE_1ST)
- {
- m_state = STATE_PICTURE;
- picture = m_pictures;
- if((m_decoder.m_coding_type != PIC_FLAG_CODING_TYPE_B) ^ (m_picture >= m_pictures + 2))
- picture += 2;
- }
- else
- {
- m_state = STATE_PICTURE_2ND;
- picture = m_picture + 1; /* second field picture */
- }
-
- m_picture = picture;
- }
-
- m_picture->flags = 0;
-
- if(m_num_pts)
- {
- if(m_bytes_since_pts >= 4)
- {
- m_num_pts = 0;
- m_picture->pts = m_pts_current;
- m_picture->flags = PIC_FLAG_PTS;
- }
- else if(m_num_pts > 1)
- {
- m_num_pts = 1;
- m_picture->pts = m_pts_previous;
- m_picture->flags = PIC_FLAG_PTS;
- }
- }
-
- m_picture->display_offset[0].x =
- m_picture->display_offset[1].x =
- m_picture->display_offset[2].x = m_display_offset_x;
- m_picture->display_offset[0].y =
- m_picture->display_offset[1].y =
- m_picture->display_offset[2].y = m_display_offset_y;
-
- return mpeg2_parse_header();
-}
-
-int CMpeg2Dec::mpeg2_header_picture()
-{
- uint8_t* buffer = m_chunk_start;
- mpeg2_picture_t* picture = m_picture;
- int type;
- int low_delay;
-
- type = (buffer [1] >> 3) & 7;
- low_delay = m_sequence.flags & SEQ_FLAG_LOW_DELAY;
-
- if(m_state == STATE_PICTURE)
- {
- mpeg2_picture_t* other;
-
- m_decoder.m_second_field = 0;
- other = m_pictures;
- if(other == picture)
- other += 2;
- if(m_decoder.m_coding_type != PIC_FLAG_CODING_TYPE_B)
- {
- m_fbuf[2] = m_fbuf[1];
- m_fbuf[1] = m_fbuf[0];
- }
- m_fbuf[0] = NULL;
- m_info.Reset();
- m_info.m_current_picture = picture;
- m_info.m_display_picture = picture;
- if(type != PIC_FLAG_CODING_TYPE_B)
- {
- if(!low_delay)
- {
- if(m_first) {
- m_info.m_display_picture = NULL;
- m_first = false;
- }
- else
- {
- m_info.m_display_picture = other;
- if(other->nb_fields == 1)
- m_info.m_display_picture_2nd = other + 1;
- m_info.m_display_fbuf = m_fbuf[1];
- }
- }
-
- if(!low_delay + !NULL/*m_convert_start*/)
- m_info.m_discard_fbuf = m_fbuf[!low_delay + !NULL/*m_convert_start*/];
- }
-
- while(m_alloc_index < 3)
- {
- mpeg2_fbuf_t* fbuf = &m_fbuf_alloc[m_alloc_index++];
- fbuf->id = NULL;
-
- int size = m_decoder.m_width * m_decoder.m_height;
- fbuf->buf[0] = (uint8_t*)_aligned_malloc(6 * size >> 2, 16);
- fbuf->buf[1] = fbuf->buf[0] + size;
- fbuf->buf[2] = fbuf->buf[1] + (size >> 2);
- memset(fbuf->buf[0], 0x10, size);
- memset(fbuf->buf[1], 0x80, size >> 2);
- memset(fbuf->buf[2], 0x80, size >> 2);
- }
- mpeg2_set_fbuf(type);
- }
- else
- {
- m_decoder.m_second_field = 1;
- m_info.m_current_picture_2nd = picture;
- m_info.m_user_data = NULL; m_info.m_user_data_len = 0;
- if(low_delay || type == PIC_FLAG_CODING_TYPE_B)
- m_info.m_display_picture_2nd = picture;
- }
- m_ext_state = PIC_CODING_EXT;
-
- picture->temporal_reference = (buffer[0] << 2) | (buffer[1] >> 6);
-
- m_decoder.m_coding_type = type;
- picture->flags |= type;
-
- if(type == PIC_FLAG_CODING_TYPE_P || type == PIC_FLAG_CODING_TYPE_B)
- {
- /* forward_f_code and backward_f_code - used in mpeg1 only */
- m_decoder.m_f_motion.f_code[1] = (buffer[3] >> 2) & 1;
- m_decoder.m_f_motion.f_code[0] = (((buffer[3] << 1) | (buffer[4] >> 7)) & 7) - 1;
- m_decoder.m_b_motion.f_code[1] = (buffer[4] >> 6) & 1;
- m_decoder.m_b_motion.f_code[0] = ((buffer[4] >> 3) & 7) - 1;
- }
-
- /* XXXXXX decode extra_information_picture as well */
-
- picture->nb_fields = 2;
-
- m_decoder.m_intra_dc_precision = 0;
- m_decoder.m_frame_pred_frame_dct = 1;
- m_decoder.m_q_scale_type = 0;
- m_decoder.m_concealment_motion_vectors = 0;
- m_decoder.m_scan = mpeg2_scan_norm_2;
- m_decoder.m_picture_structure = FRAME_PICTURE;
- m_copy_matrix = 0;
-
- return 0;
-}
-
-int CMpeg2Dec::mpeg2_header_extension()
-{
- static int (CMpeg2Dec::* parser[]) () =
- {
- NULL,
- &CMpeg2Dec::sequence_ext,
- &CMpeg2Dec::sequence_display_ext,
- &CMpeg2Dec::quant_matrix_ext,
- &CMpeg2Dec::copyright_ext,
- NULL, NULL,
- &CMpeg2Dec::picture_display_ext,
- &CMpeg2Dec::picture_coding_ext
- };
-
- int ext, ext_bit;
-
- ext = m_chunk_start[0] >> 4;
- ext_bit = 1 << ext;
-
- if(!(m_ext_state & ext_bit)) /* ignore illegal extensions */
- return 0;
- m_ext_state &= ~ext_bit;
- return (this->*parser[ext])();
-}
-
-int CMpeg2Dec::mpeg2_header_user_data()
-{
- if(!m_info.m_user_data_len) m_info.m_user_data = m_chunk_start;
- else m_info.m_user_data_len += 3;
-
- m_info.m_user_data_len += (m_chunk_ptr - 4 - m_chunk_start);
- m_chunk_start = m_chunk_ptr - 1;
-
- return 0;
-}
-
-void CMpeg2Dec::mpeg2_header_matrix_finalize()
-{
- if(m_copy_matrix & 1)
- memcpy(m_decoder.m_intra_quantizer_matrix, m_intra_quantizer_matrix, 64);
-
- if(m_copy_matrix & 2)
- memcpy(m_decoder.m_non_intra_quantizer_matrix, m_non_intra_quantizer_matrix, 64);
-}
-
-void mpeg2_sequence_t::finalize()
-{
- int w, h;
-
- byte_rate *= 50;
-
- if(flags & SEQ_FLAG_MPEG2)
- {
- switch(pixel_width)
- {
- case 1: /* square pixels */
- pixel_width = pixel_height = 1; return;
- case 2: /* 4:3 aspect ratio */
- w = 4; h = 3; break;
- case 3: /* 16:9 aspect ratio */
- w = 16; h = 9; break;
- case 4: /* 2.21:1 aspect ratio */
- w = 221; h = 100; break;
- default: /* illegal */
- pixel_width = pixel_height = 0; return;
- }
-
- w *= display_height;
- h *= display_width;
- }
- else
- {
- if(byte_rate == 50 * 0x3ffff)
- byte_rate = 0; /* mpeg-1 VBR */
-
- switch(pixel_width)
- {
- case 0: case 15: /* illegal */
- pixel_width = pixel_height = 0; return;
- case 1: /* square pixels */
- pixel_width = pixel_height = 1; return;
- case 3: /* 720x576 16:9 */
- pixel_width = 64; pixel_height = 45; return;
- case 6: /* 720x480 16:9 */
- pixel_width = 32; pixel_height = 27; return;
- case 12: /* 720*480 4:3 */
- pixel_width = 8; pixel_height = 9; return;
- default:
- h = 88 * pixel_width + 1171;
- w = 2000;
- }
- }
-
- pixel_width = w;
- pixel_height = h;
-
- /* find greatest common divisor */
- while(w) {int tmp = w; w = h % tmp; h = tmp;}
-
- pixel_width /= h;
- pixel_height /= h;
-}
-
-void CMpeg2Dec::mpeg2_header_sequence_finalize()
-{
- mpeg2_sequence_t* sequence = &m_new_sequence;
-
- sequence->finalize();
-
- mpeg2_header_matrix_finalize();
-
- m_decoder.m_mpeg1 = !(sequence->flags & SEQ_FLAG_MPEG2);
- m_decoder.m_width = sequence->width;
- m_decoder.m_height = sequence->height;
- m_decoder.m_vertical_position_extension = (sequence->picture_height > 2800);
-
- /*
- * according to 6.1.1.6, repeat sequence headers should be
- * identical to the original. However some DVDs dont respect that
- * and have different bitrates in the repeat sequence headers. So
- * we'll ignore that in the comparison and still consider these as
- * repeat sequence headers.
- */
-
- // EDIT: some dvds will work if we allow the last three fields to vary (which aren't needed anyway)
- // EDIT2: vbv_buffer_size can be ignored as well, not used by libmpeg2
-
- m_sequence.byte_rate = sequence->byte_rate;
- m_sequence.vbv_buffer_size = sequence->vbv_buffer_size;
-
- if(!memcmp(&m_sequence, sequence, FIELD_OFFSET(mpeg2_sequence_t, colour_primaries) /*sizeof(mpeg2_sequence_t)*/))
- {
- m_state = STATE_SEQUENCE_REPEATED;
- }
- else if(m_sequence.width != (unsigned)-1)
- {
- m_action = &CMpeg2Dec::mpeg2_seek_sequence;
- m_state = STATE_INVALID; /* XXXX STATE_INVALID_END ? */
- return;
- }
-
- m_sequence = *sequence;
- m_info.m_sequence = &m_sequence;
-}
-
-mpeg2_state_t CMpeg2Dec::mpeg2_header_slice_start()
-{
- m_info.m_user_data = NULL;
- m_info.m_user_data_len = 0;
- m_state = (m_picture->nb_fields > 1 || m_state == STATE_PICTURE_2ND) ? STATE_SLICE : STATE_SLICE_1ST;
-
- if(!m_nb_decode_slices)
- {
- m_picture->flags |= PIC_FLAG_SKIP;
- }
- else
- {
- int b_type = m_decoder.m_coding_type == B_TYPE;
- m_decoder.mpeg2_init_fbuf(m_fbuf[0]->buf, m_fbuf[b_type + 1]->buf, m_fbuf[b_type]->buf);
- }
-
- m_action = NULL;
-
- return (mpeg2_state_t)-1;
-}
-
-mpeg2_state_t CMpeg2Dec::mpeg2_header_end()
-{
- mpeg2_picture_t* picture = m_pictures;
-
- int b_type = m_decoder.m_coding_type == B_TYPE;
-
- if((m_picture >= picture + 2) ^ b_type)
- picture = m_pictures + 2;
-
- m_state = STATE_END;
- m_info.Reset();
-
- if(!(m_sequence.flags & SEQ_FLAG_LOW_DELAY))
- {
- m_info.m_display_picture = picture;
- if(picture->nb_fields == 1)
- m_info.m_display_picture_2nd = picture + 1;
- m_info.m_display_fbuf = m_fbuf[b_type];
- m_info.m_discard_fbuf = m_fbuf[b_type + 1];
- }
- else
- {
- m_info.m_discard_fbuf = m_fbuf[b_type];
- }
-
- m_action = &CMpeg2Dec::mpeg2_seek_sequence;
- m_first = true;
-
- return STATE_END;
-}
-
-void CMpeg2Dec::mpeg2_set_fbuf(int coding_type)
-{
- for(int i = 0; i < 3; i++)
- {
- if(m_fbuf[1] != &m_fbuf_alloc[i] && m_fbuf[2] != &m_fbuf_alloc[i])
- {
- m_fbuf[0] = &m_fbuf_alloc[i];
- m_info.m_current_fbuf = m_fbuf[0];
- if(coding_type == B_TYPE || (m_sequence.flags & SEQ_FLAG_LOW_DELAY))
- {
- if(coding_type == B_TYPE)
- m_info.m_discard_fbuf = m_fbuf[0];
- m_info.m_display_fbuf = m_fbuf[0];
- }
- break;
- }
- }
-}
-
-//
-
-int CMpeg2Dec::sequence_ext()
-{
- uint8_t* buffer = m_chunk_start;
- mpeg2_sequence_t* sequence = &m_new_sequence;
-
- if(!(buffer[3]&1))
- return 1;
-
- sequence->profile_level_id = (buffer[0] << 4) | (buffer[1] >> 4);
-
- sequence->display_width =
- sequence->picture_width += ((buffer[1] << 13) | (buffer[2] << 5)) & 0x3000;
- sequence->display_height =
- sequence->picture_height += (buffer[2] << 7) & 0x3000;
-
- sequence->width = (sequence->picture_width + 15) & ~15;
- sequence->height = (sequence->picture_height + 15) & ~15;
-
- sequence->flags |= SEQ_FLAG_MPEG2;
-
- if(!(buffer[1] & 8))
- {
- sequence->flags &= ~SEQ_FLAG_PROGRESSIVE_SEQUENCE;
- sequence->width = (sequence->width + 31) & ~31;
- sequence->height = (sequence->height + 31) & ~31;
- }
-
- if(buffer[5] & 0x80)
- {
- sequence->flags |= SEQ_FLAG_LOW_DELAY;
- }
-
- sequence->chroma_width = sequence->width;
- sequence->chroma_height = sequence->height;
-
- switch(buffer[1] & 6)
- {
- case 0: /* invalid */
- return 1;
- case 2: /* 4:2:0 */
- sequence->chroma_height >>= 1;
- case 4: /* 4:2:2 */
- sequence->chroma_width >>= 1;
- }
-
- sequence->byte_rate += ((buffer[2]<<25) | (buffer[3]<<17)) & 0x3ffc0000;
-
- sequence->vbv_buffer_size |= buffer[4] << 21;
-
- sequence->frame_period =
- sequence->frame_period * ((buffer[5]&31)+1) / (((buffer[5]>>2)&3)+1);
-
- m_ext_state = SEQ_DISPLAY_EXT;
-
- return 0;
-}
-
-int CMpeg2Dec::sequence_display_ext()
-{
- uint8_t* buffer = m_chunk_start;
- mpeg2_sequence_t* sequence = &m_new_sequence;
-
- uint32_t flags = (sequence->flags & ~SEQ_MASK_VIDEO_FORMAT) | ((buffer[0]<<4) & SEQ_MASK_VIDEO_FORMAT);
- if(buffer[0] & 1)
- {
- flags |= SEQ_FLAG_COLOUR_DESCRIPTION;
- sequence->colour_primaries = buffer[1];
- sequence->transfer_characteristics = buffer[2];
- sequence->matrix_coefficients = buffer[3];
- buffer += 3;
- }
-
- if(!(buffer[2] & 2)) /* missing marker_bit */
- return 1;
-
- // ???
-// sequence->flags = flags;
-
- sequence->display_width = (buffer[1] << 6) | (buffer[2] >> 2);
- sequence->display_height = ((buffer[2]& 1 ) << 13) | (buffer[3] << 5) | (buffer[4] >> 3);
-
- return 0;
-}
-
-int CMpeg2Dec::quant_matrix_ext()
-{
- uint8_t* buffer = m_chunk_start;
-
- if(buffer[0] & 8)
- {
- for(int i = 0; i < 64; i++)
- m_intra_quantizer_matrix[mpeg2_scan_norm_2[i]] = (buffer[i] << 5) | (buffer[i+1] >> 3);
- m_copy_matrix |= 1;
- buffer += 64;
- }
-
- if(buffer[0] & 4)
- {
- for(int i = 0; i < 64; i++)
- m_non_intra_quantizer_matrix[mpeg2_scan_norm_2[i]] = (buffer[i] << 6) | (buffer[i+1] >> 2);
- m_copy_matrix |= 2;
- }
-
- return 0;
-}
-
-int CMpeg2Dec::copyright_ext()
-{
- return 0;
-}
-
-int CMpeg2Dec::picture_display_ext()
-{
- uint8_t* buffer = m_chunk_start;
- mpeg2_picture_t* picture = m_picture;
-
- int nb_pos = picture->nb_fields;
- if(m_sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)
- nb_pos >>= 1;
-
- int i = 0;
-
- for(; i < nb_pos; i++)
- {
- int x = ((buffer[4*i] << 24) | (buffer[4*i+1] << 16) |
- (buffer[4*i+2] << 8) | buffer[4*i+3]) >> (11-2*i);
- int y = ((buffer[4*i+2] << 24) | (buffer[4*i+3] << 16) |
- (buffer[4*i+4] << 8) | buffer[4*i+5]) >> (10-2*i);
- if(!(x&y&1))
- return 1;
-
- picture->display_offset[i].x = m_display_offset_x = x >> 1;
- picture->display_offset[i].y = m_display_offset_y = y >> 1;
- }
-
- for(; i < 3; i++)
- {
- picture->display_offset[i].x = m_display_offset_x;
- picture->display_offset[i].y = m_display_offset_y;
- }
-
- return 0;
-}
-
-int CMpeg2Dec::picture_coding_ext()
-{
- uint8_t* buffer = m_chunk_start;
- mpeg2_picture_t* picture = m_picture;
-
- /* pre subtract 1 for use later in compute_motion_vector */
- m_decoder.m_f_motion.f_code[0] = (buffer[0] & 15) - 1;
- m_decoder.m_f_motion.f_code[1] = (buffer[1] >> 4) - 1;
- m_decoder.m_b_motion.f_code[0] = (buffer[1] & 15) - 1;
- m_decoder.m_b_motion.f_code[1] = (buffer[2] >> 4) - 1;
-
- m_decoder.m_intra_dc_precision = (buffer[2] >> 2) & 3;
- m_decoder.m_picture_structure = buffer[2] & 3;
- switch(m_decoder.m_picture_structure)
- {
- case TOP_FIELD:
- picture->flags |= PIC_FLAG_TOP_FIELD_FIRST;
- case BOTTOM_FIELD:
- picture->nb_fields = 1;
- break;
- case FRAME_PICTURE:
- if(!(m_sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE))
- {
- picture->nb_fields = (buffer[3] & 2) ? 3 : 2;
- picture->flags |= (buffer[3] & 128) ? PIC_FLAG_TOP_FIELD_FIRST : 0;
- }
- else
- {
- picture->nb_fields = (buffer[3]&2) ? ((buffer[3]&128) ? 6 : 4) : 2;
- }
- break;
- default:
- return 1;
- }
-
- m_decoder.m_top_field_first = buffer[3] >> 7;
- m_decoder.m_frame_pred_frame_dct = (buffer[3] >> 6) & 1;
- m_decoder.m_concealment_motion_vectors = (buffer[3] >> 5) & 1;
- m_decoder.m_q_scale_type = (buffer[3] >> 4) & 1;
- m_decoder.m_intra_vlc_format = (buffer[3] >> 3) & 1;
- m_decoder.m_scan = (buffer[3] & 4) ? mpeg2_scan_alt_2 : mpeg2_scan_norm_2;
-
- if(buffer[3] & 2)
- picture->flags |= PIC_FLAG_REPEAT_FIRST_FIELD;
-
- picture->flags |= (buffer[4] & 0x80) ? PIC_FLAG_PROGRESSIVE_FRAME : 0;
- if(buffer[4] & 0x40)
- picture->flags |= (((buffer[4]<<26) | (buffer[5]<<18) | (buffer[6]<<10)) & PIC_MASK_COMPOSITE_DISPLAY) | PIC_FLAG_COMPOSITE_DISPLAY;
-
- m_ext_state = PIC_DISPLAY_EXT | COPYRIGHT_EXT | QUANT_MATRIX_EXT;
-
- return 0;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////////////////////
-
-// vlc
-
-#define GETWORD(bit_buf,shift,bit_ptr) \
-do { \
- bit_buf |= ((bit_ptr[0] << 8) | bit_ptr[1]) << (shift); \
- bit_ptr += 2; \
-} while (0)
-/*
-void bitstream_init(const uint8_t * start)
-{
- m_bitstream_buf =
- (start[0] << 24) | (start[1] << 16) | (start[2] << 8) | start[3];
- m_bitstream_ptr = start + 4;
- m_bitstream_bits = -16;
-}
-*/
-/* make sure that there are at least 16 valid bits in bit_buf */
-#define NEEDBITS \
-do { \
- if (bits > 0) { \
- GETWORD (bit_buf, bits, bit_ptr); \
- bits -= 16; \
- } \
-} while (0)
-
-/* remove num valid bits from bit_buf */
-#define DUMPBITS(num) \
-do { \
- bit_buf <<= (num); \
- bits += (num); \
-} while (0)
-
-/* take num bits from the high part of bit_buf and zero extend them */
-#define UBITS(bit_buf,num) (((uint32_t)(bit_buf)) >> (32 - (num)))
-
-/* take num bits from the high part of bit_buf and sign extend them */
-#define SBITS(bit_buf,num) (((int32_t)(bit_buf)) >> (32 - (num)))
-
-typedef struct {
- uint8_t modes;
- uint8_t len;
-} MBtab;
-
-typedef struct {
- uint8_t delta;
- uint8_t len;
-} MVtab;
-
-typedef struct {
- int8_t dmv;
- uint8_t len;
-} DMVtab;
-
-typedef struct {
- uint8_t cbp;
- uint8_t len;
-} CBPtab;
-
-typedef struct {
- uint8_t size;
- uint8_t len;
-} DCtab;
-
-typedef struct {
- uint8_t run;
- uint8_t level;
- uint8_t len;
-} DCTtab;
-
-typedef struct {
- uint8_t mba;
- uint8_t len;
-} MBAtab;
-
-
-#define INTRA MACROBLOCK_INTRA
-#define QUANT MACROBLOCK_QUANT
-
-static const MBtab MB_I [] = {
- {INTRA|QUANT, 2}, {INTRA, 1}
-};
-
-#define MC MACROBLOCK_MOTION_FORWARD
-#define CODED MACROBLOCK_PATTERN
-
-static const MBtab MB_P [] = {
- {INTRA|QUANT, 6}, {CODED|QUANT, 5}, {MC|CODED|QUANT, 5}, {INTRA, 5},
- {MC, 3}, {MC, 3}, {MC, 3}, {MC, 3},
- {CODED, 2}, {CODED, 2}, {CODED, 2}, {CODED, 2},
- {CODED, 2}, {CODED, 2}, {CODED, 2}, {CODED, 2},
- {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1},
- {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1},
- {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1},
- {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}
-};
-
-#define FWD MACROBLOCK_MOTION_FORWARD
-#define BWD MACROBLOCK_MOTION_BACKWARD
-#define INTER MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD
-
-static const MBtab MB_B [] = {
- {0, 0}, {INTRA|QUANT, 6},
- {BWD|CODED|QUANT, 6}, {FWD|CODED|QUANT, 6},
- {INTER|CODED|QUANT, 5}, {INTER|CODED|QUANT, 5},
- {INTRA, 5}, {INTRA, 5},
- {FWD, 4}, {FWD, 4}, {FWD, 4}, {FWD, 4},
- {FWD|CODED, 4}, {FWD|CODED, 4}, {FWD|CODED, 4}, {FWD|CODED, 4},
- {BWD, 3}, {BWD, 3}, {BWD, 3}, {BWD, 3},
- {BWD, 3}, {BWD, 3}, {BWD, 3}, {BWD, 3},
- {BWD|CODED, 3}, {BWD|CODED, 3}, {BWD|CODED, 3}, {BWD|CODED, 3},
- {BWD|CODED, 3}, {BWD|CODED, 3}, {BWD|CODED, 3}, {BWD|CODED, 3},
- {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2},
- {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2},
- {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2},
- {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2},
- {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2},
- {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2},
- {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2},
- {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}
-};
-
-#undef INTRA
-#undef QUANT
-#undef MC
-#undef CODED
-#undef FWD
-#undef BWD
-#undef INTER
-
-
-static const MVtab MV_4 [] = {
- { 3, 6}, { 2, 4}, { 1, 3}, { 1, 3}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}
-};
-
-static const MVtab MV_10 [] = {
- { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10},
- { 0,10}, { 0,10}, { 0,10}, { 0,10}, {15,10}, {14,10}, {13,10}, {12,10},
- {11,10}, {10,10}, { 9, 9}, { 9, 9}, { 8, 9}, { 8, 9}, { 7, 9}, { 7, 9},
- { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7},
- { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7},
- { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}
-};
-
-
-static const DMVtab DMV_2 [] = {
- { 0, 1}, { 0, 1}, { 1, 2}, {-1, 2}
-};
-
-
-static const CBPtab CBP_7 [] = {
- {0x22, 7}, {0x12, 7}, {0x0a, 7}, {0x06, 7},
- {0x21, 7}, {0x11, 7}, {0x09, 7}, {0x05, 7},
- {0x3f, 6}, {0x3f, 6}, {0x03, 6}, {0x03, 6},
- {0x24, 6}, {0x24, 6}, {0x18, 6}, {0x18, 6},
- {0x3e, 5}, {0x3e, 5}, {0x3e, 5}, {0x3e, 5},
- {0x02, 5}, {0x02, 5}, {0x02, 5}, {0x02, 5},
- {0x3d, 5}, {0x3d, 5}, {0x3d, 5}, {0x3d, 5},
- {0x01, 5}, {0x01, 5}, {0x01, 5}, {0x01, 5},
- {0x38, 5}, {0x38, 5}, {0x38, 5}, {0x38, 5},
- {0x34, 5}, {0x34, 5}, {0x34, 5}, {0x34, 5},
- {0x2c, 5}, {0x2c, 5}, {0x2c, 5}, {0x2c, 5},
- {0x1c, 5}, {0x1c, 5}, {0x1c, 5}, {0x1c, 5},
- {0x28, 5}, {0x28, 5}, {0x28, 5}, {0x28, 5},
- {0x14, 5}, {0x14, 5}, {0x14, 5}, {0x14, 5},
- {0x30, 5}, {0x30, 5}, {0x30, 5}, {0x30, 5},
- {0x0c, 5}, {0x0c, 5}, {0x0c, 5}, {0x0c, 5},
- {0x20, 4}, {0x20, 4}, {0x20, 4}, {0x20, 4},
- {0x20, 4}, {0x20, 4}, {0x20, 4}, {0x20, 4},
- {0x10, 4}, {0x10, 4}, {0x10, 4}, {0x10, 4},
- {0x10, 4}, {0x10, 4}, {0x10, 4}, {0x10, 4},
- {0x08, 4}, {0x08, 4}, {0x08, 4}, {0x08, 4},
- {0x08, 4}, {0x08, 4}, {0x08, 4}, {0x08, 4},
- {0x04, 4}, {0x04, 4}, {0x04, 4}, {0x04, 4},
- {0x04, 4}, {0x04, 4}, {0x04, 4}, {0x04, 4},
- {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3},
- {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3},
- {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3},
- {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}
-};
-
-static const CBPtab CBP_9 [] = {
- {0, 0}, {0x00, 9}, {0x27, 9}, {0x1b, 9},
- {0x3b, 9}, {0x37, 9}, {0x2f, 9}, {0x1f, 9},
- {0x3a, 8}, {0x3a, 8}, {0x36, 8}, {0x36, 8},
- {0x2e, 8}, {0x2e, 8}, {0x1e, 8}, {0x1e, 8},
- {0x39, 8}, {0x39, 8}, {0x35, 8}, {0x35, 8},
- {0x2d, 8}, {0x2d, 8}, {0x1d, 8}, {0x1d, 8},
- {0x26, 8}, {0x26, 8}, {0x1a, 8}, {0x1a, 8},
- {0x25, 8}, {0x25, 8}, {0x19, 8}, {0x19, 8},
- {0x2b, 8}, {0x2b, 8}, {0x17, 8}, {0x17, 8},
- {0x33, 8}, {0x33, 8}, {0x0f, 8}, {0x0f, 8},
- {0x2a, 8}, {0x2a, 8}, {0x16, 8}, {0x16, 8},
- {0x32, 8}, {0x32, 8}, {0x0e, 8}, {0x0e, 8},
- {0x29, 8}, {0x29, 8}, {0x15, 8}, {0x15, 8},
- {0x31, 8}, {0x31, 8}, {0x0d, 8}, {0x0d, 8},
- {0x23, 8}, {0x23, 8}, {0x13, 8}, {0x13, 8},
- {0x0b, 8}, {0x0b, 8}, {0x07, 8}, {0x07, 8}
-};
-
-
-static const DCtab DC_lum_5 [] = {
- {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}
-};
-
-static const DCtab DC_chrom_5 [] = {
- {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}
-};
-
-static const DCtab DC_long [] = {
- {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, { 6, 5}, { 6, 5},
- {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, { 6, 5}, { 6, 5},
- {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}
-};
-
-
-static const DCTtab DCT_16 [] = {
- {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0},
- {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0},
- {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0},
- {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0},
- { 2,18, 0}, { 2,17, 0}, { 2,16, 0}, { 2,15, 0},
- { 7, 3, 0}, { 17, 2, 0}, { 16, 2, 0}, { 15, 2, 0},
- { 14, 2, 0}, { 13, 2, 0}, { 12, 2, 0}, { 32, 1, 0},
- { 31, 1, 0}, { 30, 1, 0}, { 29, 1, 0}, { 28, 1, 0}
-};
-
-static const DCTtab DCT_15 [] = {
- { 1,40,15}, { 1,39,15}, { 1,38,15}, { 1,37,15},
- { 1,36,15}, { 1,35,15}, { 1,34,15}, { 1,33,15},
- { 1,32,15}, { 2,14,15}, { 2,13,15}, { 2,12,15},
- { 2,11,15}, { 2,10,15}, { 2, 9,15}, { 2, 8,15},
- { 1,31,14}, { 1,31,14}, { 1,30,14}, { 1,30,14},
- { 1,29,14}, { 1,29,14}, { 1,28,14}, { 1,28,14},
- { 1,27,14}, { 1,27,14}, { 1,26,14}, { 1,26,14},
- { 1,25,14}, { 1,25,14}, { 1,24,14}, { 1,24,14},
- { 1,23,14}, { 1,23,14}, { 1,22,14}, { 1,22,14},
- { 1,21,14}, { 1,21,14}, { 1,20,14}, { 1,20,14},
- { 1,19,14}, { 1,19,14}, { 1,18,14}, { 1,18,14},
- { 1,17,14}, { 1,17,14}, { 1,16,14}, { 1,16,14}
-};
-
-static const DCTtab DCT_13 [] = {
- { 11, 2,13}, { 10, 2,13}, { 6, 3,13}, { 4, 4,13},
- { 3, 5,13}, { 2, 7,13}, { 2, 6,13}, { 1,15,13},
- { 1,14,13}, { 1,13,13}, { 1,12,13}, { 27, 1,13},
- { 26, 1,13}, { 25, 1,13}, { 24, 1,13}, { 23, 1,13},
- { 1,11,12}, { 1,11,12}, { 9, 2,12}, { 9, 2,12},
- { 5, 3,12}, { 5, 3,12}, { 1,10,12}, { 1,10,12},
- { 3, 4,12}, { 3, 4,12}, { 8, 2,12}, { 8, 2,12},
- { 22, 1,12}, { 22, 1,12}, { 21, 1,12}, { 21, 1,12},
- { 1, 9,12}, { 1, 9,12}, { 20, 1,12}, { 20, 1,12},
- { 19, 1,12}, { 19, 1,12}, { 2, 5,12}, { 2, 5,12},
- { 4, 3,12}, { 4, 3,12}, { 1, 8,12}, { 1, 8,12},
- { 7, 2,12}, { 7, 2,12}, { 18, 1,12}, { 18, 1,12}
-};
-
-static const DCTtab DCT_B14_10 [] = {
- { 17, 1,10}, { 6, 2,10}, { 1, 7,10}, { 3, 3,10},
- { 2, 4,10}, { 16, 1,10}, { 15, 1,10}, { 5, 2,10}
-};
-
-static const DCTtab DCT_B14_8 [] = {
- { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6},
- { 3, 2, 7}, { 3, 2, 7}, { 10, 1, 7}, { 10, 1, 7},
- { 1, 4, 7}, { 1, 4, 7}, { 9, 1, 7}, { 9, 1, 7},
- { 8, 1, 6}, { 8, 1, 6}, { 8, 1, 6}, { 8, 1, 6},
- { 7, 1, 6}, { 7, 1, 6}, { 7, 1, 6}, { 7, 1, 6},
- { 2, 2, 6}, { 2, 2, 6}, { 2, 2, 6}, { 2, 2, 6},
- { 6, 1, 6}, { 6, 1, 6}, { 6, 1, 6}, { 6, 1, 6},
- { 14, 1, 8}, { 1, 6, 8}, { 13, 1, 8}, { 12, 1, 8},
- { 4, 2, 8}, { 2, 3, 8}, { 1, 5, 8}, { 11, 1, 8}
-};
-
-static const DCTtab DCT_B14AC_5 [] = {
- { 1, 3, 5}, { 5, 1, 5}, { 4, 1, 5},
- { 1, 2, 4}, { 1, 2, 4}, { 3, 1, 4}, { 3, 1, 4},
- { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3},
- {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2},
- {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}
-};
-
-static const DCTtab DCT_B14DC_5 [] = {
- { 1, 3, 5}, { 5, 1, 5}, { 4, 1, 5},
- { 1, 2, 4}, { 1, 2, 4}, { 3, 1, 4}, { 3, 1, 4},
- { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3},
- { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1},
- { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1},
- { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1},
- { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}
-};
-
-static const DCTtab DCT_B15_10 [] = {
- { 6, 2, 9}, { 6, 2, 9}, { 15, 1, 9}, { 15, 1, 9},
- { 3, 4,10}, { 17, 1,10}, { 16, 1, 9}, { 16, 1, 9}
-};
-
-static const DCTtab DCT_B15_8 [] = {
- { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6},
- { 8, 1, 7}, { 8, 1, 7}, { 9, 1, 7}, { 9, 1, 7},
- { 7, 1, 7}, { 7, 1, 7}, { 3, 2, 7}, { 3, 2, 7},
- { 1, 7, 6}, { 1, 7, 6}, { 1, 7, 6}, { 1, 7, 6},
- { 1, 6, 6}, { 1, 6, 6}, { 1, 6, 6}, { 1, 6, 6},
- { 5, 1, 6}, { 5, 1, 6}, { 5, 1, 6}, { 5, 1, 6},
- { 6, 1, 6}, { 6, 1, 6}, { 6, 1, 6}, { 6, 1, 6},
- { 2, 5, 8}, { 12, 1, 8}, { 1,11, 8}, { 1,10, 8},
- { 14, 1, 8}, { 13, 1, 8}, { 4, 2, 8}, { 2, 4, 8},
- { 3, 1, 5}, { 3, 1, 5}, { 3, 1, 5}, { 3, 1, 5},
- { 3, 1, 5}, { 3, 1, 5}, { 3, 1, 5}, { 3, 1, 5},
- { 2, 2, 5}, { 2, 2, 5}, { 2, 2, 5}, { 2, 2, 5},
- { 2, 2, 5}, { 2, 2, 5}, { 2, 2, 5}, { 2, 2, 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},
- { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3},
- { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3},
- { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3},
- { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3},
- { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3},
- { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3},
- { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3},
- { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3},
- {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4},
- {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4},
- {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4},
- {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4},
- { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4},
- { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4},
- { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4},
- { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2},
- { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3},
- { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3},
- { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3},
- { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3},
- { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3},
- { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3},
- { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3},
- { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3},
- { 1, 4, 5}, { 1, 4, 5}, { 1, 4, 5}, { 1, 4, 5},
- { 1, 4, 5}, { 1, 4, 5}, { 1, 4, 5}, { 1, 4, 5},
- { 1, 5, 5}, { 1, 5, 5}, { 1, 5, 5}, { 1, 5, 5},
- { 1, 5, 5}, { 1, 5, 5}, { 1, 5, 5}, { 1, 5, 5},
- { 10, 1, 7}, { 10, 1, 7}, { 2, 3, 7}, { 2, 3, 7},
- { 11, 1, 7}, { 11, 1, 7}, { 1, 8, 7}, { 1, 8, 7},
- { 1, 9, 7}, { 1, 9, 7}, { 1,12, 8}, { 1,13, 8},
- { 3, 3, 8}, { 5, 2, 8}, { 1,14, 8}, { 1,15, 8}
-};
-
-
-static const MBAtab MBA_5 [] = {
- {6, 5}, {5, 5}, {4, 4}, {4, 4}, {3, 4}, {3, 4},
- {2, 3}, {2, 3}, {2, 3}, {2, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
- {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1},
- {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}
-};
-
-static const MBAtab MBA_11 [] = {
- {32, 11}, {31, 11}, {30, 11}, {29, 11},
- {28, 11}, {27, 11}, {26, 11}, {25, 11},
- {24, 11}, {23, 11}, {22, 11}, {21, 11},
- {20, 10}, {20, 10}, {19, 10}, {19, 10},
- {18, 10}, {18, 10}, {17, 10}, {17, 10},
- {16, 10}, {16, 10}, {15, 10}, {15, 10},
- {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, 8}, { 9, 8}, { 9, 8}, { 9, 8},
- { 9, 8}, { 9, 8}, { 9, 8}, { 9, 8},
- { 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},
- { 7, 7}, { 7, 7}, { 7, 7}, { 7, 7},
- { 7, 7}, { 7, 7}, { 7, 7}, { 7, 7},
- { 7, 7}, { 7, 7}, { 7, 7}, { 7, 7},
- { 7, 7}, { 7, 7}, { 7, 7}, { 7, 7}
-};
-
-//////////////////////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////////////////////
-
-static int non_linear_quantizer_scale [] = {
- 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
-};
-
-bool CMpeg2Decoder::m_idct_initialized = false;
-
-CMpeg2Decoder::CMpeg2Decoder()
-{
- memset(&m_b_motion, 0, sizeof(m_b_motion));
- memset(&m_f_motion, 0, sizeof(m_f_motion));
-
- m_DCTblock = (int16_t*)_aligned_malloc(64*sizeof(int16_t), 16);
- memset(m_DCTblock, 0, 64*sizeof(int16_t));
-
- m_bitstream_buf = 0;
- m_bitstream_bits = 0;
- m_bitstream_ptr = NULL;
-
- memset(&m_dest, 0, sizeof(m_dest));
- memset(&m_picture_dest, 0, sizeof(m_picture_dest));
-
- m_offset = m_stride = m_uv_stride = 0;
- m_limit_x = m_limit_y_16 = m_limit_y_8 = m_limit_y = 0;
-
- memset(&m_dc_dct_pred, 0, sizeof(m_dc_dct_pred));
-
- m_quantizer_scale = m_dmv_offset = 0;
- m_v_offset = 0;
-
- memset(&m_intra_quantizer_matrix, 0, sizeof(m_intra_quantizer_matrix));
- memset(&m_non_intra_quantizer_matrix, 0, sizeof(m_non_intra_quantizer_matrix));
-
- m_width = m_height = 0;
- m_vertical_position_extension = 0;
-
- m_coding_type = 0;
-
- m_intra_dc_precision = 0;
- m_picture_structure = 0;
- m_frame_pred_frame_dct = 0;
- m_concealment_motion_vectors = 0;
- m_q_scale_type = 0;
- m_intra_vlc_format = 0;
- m_top_field_first = 0;
-
- m_scan = NULL;
-
- m_second_field = 0;
-
- m_mpeg1 = 0;
-
- if(g_cpuid.m_flags&CCpuID::sse2)
- {
- m_idct_init = mpeg2_idct_init_sse2;
- m_idct_copy = mpeg2_idct_copy_sse2;
- m_idct_add = mpeg2_idct_add_sse2;
- m_mc = &mpeg2_mc_sse2;
- }
-#ifndef _WIN64
- else if(g_cpuid.m_flags&CCpuID::mmx)
- {
- m_idct_init = mpeg2_idct_init_mmx;
- m_idct_copy = mpeg2_idct_copy_mmx;
- m_idct_add = mpeg2_idct_add_mmx;
- m_mc = &mpeg2_mc_mmx;
- }
- else
-#endif
- {
- m_idct_init = mpeg2_idct_init_c;
- m_idct_copy = mpeg2_idct_copy_c;
- m_idct_add = mpeg2_idct_add_c;
- m_mc = &mpeg2_mc_c;
- }
- if(!m_idct_initialized)
- {
- m_idct_init();
- m_idct_initialized = true;
- }
-}
-
-CMpeg2Decoder::~CMpeg2Decoder()
-{
- if(m_DCTblock) _aligned_free(m_DCTblock);
-}
-
-#define bit_buf (m_bitstream_buf)
-#define bits (m_bitstream_bits)
-#define bit_ptr (m_bitstream_ptr)
-
-int CMpeg2Decoder::get_macroblock_modes()
-{
- int macroblock_modes;
- const MBtab* tab;
-
- switch(m_coding_type)
- {
- case P_TYPE:
- tab = MB_P + UBITS(bit_buf, 5);
- DUMPBITS(tab->len);
- macroblock_modes = tab->modes;
-
- if(m_picture_structure != FRAME_PICTURE)
- {
- if(macroblock_modes & MACROBLOCK_MOTION_FORWARD)
- {
- macroblock_modes |= UBITS(bit_buf, 2) * MOTION_TYPE_BASE;
- DUMPBITS(2);
- }
-
- return macroblock_modes;
- }
- else if(m_frame_pred_frame_dct)
- {
- if(macroblock_modes & MACROBLOCK_MOTION_FORWARD)
- macroblock_modes |= MC_FRAME;
-
- return macroblock_modes;
- }
-
- if(macroblock_modes & MACROBLOCK_MOTION_FORWARD)
- {
- macroblock_modes |= UBITS(bit_buf, 2) * MOTION_TYPE_BASE;
- DUMPBITS(2);
- }
-
- if(macroblock_modes & (MACROBLOCK_INTRA|MACROBLOCK_PATTERN))
- {
- macroblock_modes |= UBITS(bit_buf, 1) * DCT_TYPE_INTERLACED;
- DUMPBITS(1);
- }
-
- return macroblock_modes;
-
- case B_TYPE:
- tab = MB_B + UBITS(bit_buf, 6);
- DUMPBITS(tab->len);
- macroblock_modes = tab->modes;
-
- if(m_picture_structure != FRAME_PICTURE)
- {
- if(!(macroblock_modes & MACROBLOCK_INTRA))
- {
- macroblock_modes |= UBITS(bit_buf, 2) * MOTION_TYPE_BASE;
- DUMPBITS(2);
- }
-
- return macroblock_modes;
- }
- else if(m_frame_pred_frame_dct)
- {
- // if(!(macroblock_modes & MACROBLOCK_INTRA))
- macroblock_modes |= MC_FRAME;
-
- return macroblock_modes;
- }
-/*
- if(macroblock_modes & MACROBLOCK_INTRA)
- goto intra;
-
- macroblock_modes |= UBITS(bit_buf, 2) * MOTION_TYPE_BASE;
- DUMPBITS(2);
-
- if(macroblock_modes & (MACROBLOCK_INTRA|MACROBLOCK_PATTERN))
- {
-intra:
- macroblock_modes |= UBITS(bit_buf, 1) * DCT_TYPE_INTERLACED;
- DUMPBITS(1);
- }
-*/
- if(!(macroblock_modes & MACROBLOCK_INTRA))
- {
- macroblock_modes |= UBITS(bit_buf, 2) * MOTION_TYPE_BASE;
- DUMPBITS(2);
- }
-
- if(macroblock_modes & (MACROBLOCK_INTRA|MACROBLOCK_PATTERN))
- {
- macroblock_modes |= UBITS(bit_buf, 1) * DCT_TYPE_INTERLACED;
- DUMPBITS(1);
- }
-
- return macroblock_modes;
-
- case I_TYPE:
- tab = MB_I + UBITS(bit_buf, 1);
- DUMPBITS(tab->len);
- macroblock_modes = tab->modes;
-
- if(!m_frame_pred_frame_dct && m_picture_structure == FRAME_PICTURE)
- {
- macroblock_modes |= UBITS(bit_buf, 1) * DCT_TYPE_INTERLACED;
- DUMPBITS(1);
- }
-
- return macroblock_modes;
-
- case D_TYPE:
-
- DUMPBITS(1);
- return MACROBLOCK_INTRA;
- }
-
- return 0;
-}
-
-int CMpeg2Decoder::get_quantizer_scale()
-{
- int quantizer_scale_code = UBITS(bit_buf, 5);
- DUMPBITS(5);
-
- return m_q_scale_type
- ? non_linear_quantizer_scale[quantizer_scale_code]
- : (quantizer_scale_code << 1);
-}
-
-int CMpeg2Decoder::get_motion_delta(const int f_code)
-{
- int delta;
- int sign;
- const MVtab* tab;
-
- if(bit_buf & 0x80000000)
- {
- DUMPBITS(1);
- return 0;
- }
- else if(bit_buf >= 0x0c000000)
- {
- tab = MV_4 + UBITS(bit_buf, 4);
- delta = (tab->delta << f_code) + 1;
- bits += tab->len + f_code + 1;
- bit_buf <<= tab->len;
-
- sign = SBITS(bit_buf, 1);
- bit_buf <<= 1;
-
- if(f_code)
- {
- delta += UBITS(bit_buf, f_code);
- }
-
- bit_buf <<= f_code;
-
- return (delta ^ sign) - sign;
- }
- else
- {
- tab = MV_10 + UBITS(bit_buf, 10);
- delta = (tab->delta << f_code) + 1;
- bits += tab->len + 1;
- bit_buf <<= tab->len;
-
- sign = SBITS(bit_buf, 1);
- bit_buf <<= 1;
-
- if(f_code)
- {
- NEEDBITS;
- delta += UBITS(bit_buf, f_code);
- DUMPBITS(f_code);
- }
-
- return (delta ^ sign) - sign;
- }
-}
-
-int CMpeg2Decoder::bound_motion_vector(const int vector, const int f_code)
-{
- return ((int32_t)vector << (27 - f_code)) >> (27 - f_code);
-}
-
-int CMpeg2Decoder::get_dmv()
-{
- const DMVtab* tab = DMV_2 + UBITS(bit_buf, 2);
- DUMPBITS(tab->len);
- return tab->dmv;
-}
-
-int CMpeg2Decoder::get_coded_block_pattern()
-{
- const CBPtab* tab;
-
- NEEDBITS;
-
- if(bit_buf >= 0x20000000)
- {
- tab = CBP_7 + (UBITS(bit_buf, 7) - 16);
- DUMPBITS(tab->len);
- return tab->cbp;
- }
- else
- {
- tab = CBP_9 + UBITS(bit_buf, 9);
- DUMPBITS(tab->len);
- return tab->cbp;
- }
-}
-
-int CMpeg2Decoder::get_luma_dc_dct_diff()
-{
- const DCtab* tab;
- int size;
- int dc_diff;
-
- if(bit_buf < 0xf8000000)
- {
- tab = DC_lum_5 + UBITS(bit_buf, 5);
- size = tab->size;
- if(size)
- {
- bits += tab->len + size;
- bit_buf <<= tab->len;
- dc_diff = UBITS(bit_buf, size) - UBITS(SBITS(~bit_buf, 1), size);
- bit_buf <<= size;
- return dc_diff;
- }
- else
- {
- DUMPBITS(3);
- return 0;
- }
- }
- else
- {
- tab = DC_long + (UBITS(bit_buf, 9) - 0x1e0);
- size = tab->size;
- DUMPBITS(tab->len);
- NEEDBITS;
- dc_diff = UBITS(bit_buf, size) - UBITS(SBITS(~bit_buf, 1), size);
- DUMPBITS(size);
- return dc_diff;
- }
-}
-
-int CMpeg2Decoder::get_chroma_dc_dct_diff()
-{
- const DCtab* tab;
- int size;
- int dc_diff;
-
- if(bit_buf < 0xf8000000)
- {
- tab = DC_chrom_5 + UBITS(bit_buf, 5);
- size = tab->size;
-
- if(size)
- {
- bits += tab->len + size;
- bit_buf <<= tab->len;
- dc_diff = UBITS(bit_buf, size) - UBITS(SBITS(~bit_buf, 1), size);
- bit_buf <<= size;
- return dc_diff;
- }
- else
- {
- DUMPBITS(2);
- return 0;
- }
- }
- else
- {
- tab = DC_long + (UBITS(bit_buf, 10) - 0x3e0);
- size = tab->size;
- DUMPBITS(tab->len + 1);
- NEEDBITS;
- dc_diff = UBITS(bit_buf, size) - UBITS(SBITS(~bit_buf, 1), size);
- DUMPBITS(size);
- return dc_diff;
- }
-}
-
-#undef bit_buf
-#undef bits
-#undef bit_ptr
-
-#define SATURATE(val) \
-do { \
- if((uint32_t)(val + 2048) > 4095) \
- val = SBITS(val, 1) ^ 2047; \
-} while (0)
-
-void CMpeg2Decoder::get_intra_block_B14()
-{
- int i, j;
- int val;
- const uint8_t* scan = m_scan;
- const uint8_t* quant_matrix = m_intra_quantizer_matrix;
- int quantizer_scale = m_quantizer_scale;
- int mismatch;
- const DCTtab* tab;
- uint32_t bit_buf;
- int bits;
- const uint8_t* bit_ptr;
- int16_t* dest;
-
- dest = m_DCTblock;
- i = 0;
- mismatch = ~dest[0];
-
- bit_buf = m_bitstream_buf;
- bits = m_bitstream_bits;
- bit_ptr = m_bitstream_ptr;
-
- NEEDBITS;
-
- while(1)
- {
- if(bit_buf >= 0x28000000)
- {
- tab = DCT_B14AC_5 + (UBITS(bit_buf, 5) - 5);
-
- i += tab->run;
- if(i >= 64)
- break; /* end of block */
-
-normal_code:
- j = scan[i];
- bit_buf <<= tab->len;
- bits += tab->len + 1;
- val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4;
-
- // if(bitstream_get (1)) val = -val;
- val = (val ^ SBITS(bit_buf, 1)) - SBITS(bit_buf, 1);
-
- SATURATE(val);
- dest[j] = val;
- mismatch ^= val;
-
- bit_buf <<= 1;
- NEEDBITS;
-
- continue;
- }
- else if(bit_buf >= 0x04000000)
- {
- tab = DCT_B14_8 + (UBITS(bit_buf, 8) - 4);
-
- i += tab->run;
- if(i < 64)
- goto normal_code;
-
- /* escape code */
-
- i += UBITS(bit_buf << 6, 6) - 64;
- if(i >= 64)
- break; /* illegal, check needed to avoid buffer overflow */
-
- j = scan[i];
-
- DUMPBITS(12);
- NEEDBITS;
- val = (SBITS(bit_buf, 12) * quantizer_scale * quant_matrix[j]) / 16;
-
- SATURATE(val);
- dest[j] = val;
- mismatch ^= val;
-
- DUMPBITS(12);
- NEEDBITS;
-
- continue;
- }
- else if(bit_buf >= 0x02000000)
- {
- tab = DCT_B14_10 + (UBITS(bit_buf, 10) - 8);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
- else if(bit_buf >= 0x00800000)
- {
- tab = DCT_13 + (UBITS(bit_buf, 13) - 16);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
- else if(bit_buf >= 0x00200000)
- {
- tab = DCT_15 + (UBITS(bit_buf, 15) - 16);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
- else
- {
- tab = DCT_16 + UBITS(bit_buf, 16);
- bit_buf <<= 16;
- GETWORD (bit_buf, bits + 16, bit_ptr);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
-
- break; /* illegal, check needed to avoid buffer overflow */
- }
-
- dest[63] ^= mismatch & 1;
- DUMPBITS(2); /* dump end of block code */
- m_bitstream_buf = bit_buf;
- m_bitstream_bits = bits;
- m_bitstream_ptr = bit_ptr;
-}
-
-void CMpeg2Decoder::get_intra_block_B15()
-{
- int i, j;
- int val;
- const uint8_t* scan = m_scan;
- const uint8_t* quant_matrix = m_intra_quantizer_matrix;
- int quantizer_scale = m_quantizer_scale;
- int mismatch;
- const DCTtab* tab;
- uint32_t bit_buf;
- int bits;
- const uint8_t* bit_ptr;
- int16_t* dest;
-
- dest = m_DCTblock;
- i = 0;
- mismatch = ~dest[0];
-
- bit_buf = m_bitstream_buf;
- bits = m_bitstream_bits;
- bit_ptr = m_bitstream_ptr;
-
- NEEDBITS;
-
- while(1)
- {
- if(bit_buf >= 0x04000000)
- {
- tab = DCT_B15_8 + (UBITS(bit_buf, 8) - 4);
-
- i += tab->run;
- if(i < 64)
- {
-normal_code:
- j = scan[i];
- bit_buf <<= tab->len;
- bits += tab->len + 1;
- val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4;
-
- // if(bitstream_get (1)) val = -val;
- val = (val ^ SBITS(bit_buf, 1)) - SBITS(bit_buf, 1);
-
- SATURATE(val);
- dest[j] = val;
- mismatch ^= val;
-
- bit_buf <<= 1;
- NEEDBITS;
-
- continue;
- }
- else
- {
- /* end of block. I commented out this code because if we */
- /* dont exit here we will still exit at the later test :) */
-
- /* if(i >= 128) break; */ /* end of block */
-
- /* escape code */
-
- i += UBITS(bit_buf << 6, 6) - 64;
- if(i >= 64)
- break; /* illegal, check against buffer overflow */
-
- j = scan[i];
-
- DUMPBITS(12);
- NEEDBITS;
- val = (SBITS(bit_buf, 12) *
- quantizer_scale * quant_matrix[j]) / 16;
-
- SATURATE(val);
- dest[j] = val;
- mismatch ^= val;
-
- DUMPBITS(12);
- NEEDBITS;
-
- continue;
- }
- }
- else if(bit_buf >= 0x02000000)
- {
- tab = DCT_B15_10 + (UBITS(bit_buf, 10) - 8);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
- else if(bit_buf >= 0x00800000)
- {
- tab = DCT_13 + (UBITS(bit_buf, 13) - 16);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
- else if(bit_buf >= 0x00200000)
- {
- tab = DCT_15 + (UBITS(bit_buf, 15) - 16);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
- else
- {
- tab = DCT_16 + UBITS(bit_buf, 16);
- bit_buf <<= 16;
- GETWORD(bit_buf, bits + 16, bit_ptr);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
-
- break; /* illegal, check needed to avoid buffer overflow */
- }
-
- dest[63] ^= mismatch & 1;
- DUMPBITS(4); /* dump end of block code */
- m_bitstream_buf = bit_buf;
- m_bitstream_bits = bits;
- m_bitstream_ptr = bit_ptr;
-}
-
-int CMpeg2Decoder::get_non_intra_block()
-{
- int i, j;
- int val;
- const uint8_t* scan = m_scan;
- const uint8_t* quant_matrix = m_non_intra_quantizer_matrix;
- int quantizer_scale = m_quantizer_scale;
- int mismatch;
- const DCTtab* tab;
- uint32_t bit_buf;
- int bits;
- const uint8_t* bit_ptr;
- int16_t* dest;
-
- i = -1;
- mismatch = 1;
- dest = m_DCTblock;
-
- bit_buf = m_bitstream_buf;
- bits = m_bitstream_bits;
- bit_ptr = m_bitstream_ptr;
-
- NEEDBITS;
- if(bit_buf >= 0x28000000)
- {
- tab = DCT_B14DC_5 + (UBITS(bit_buf, 5) - 5);
- goto entry_1;
- }
- else
- {
- goto entry_2;
- }
-
- while(1)
- {
- if(bit_buf >= 0x28000000)
- {
- tab = DCT_B14AC_5 + (UBITS(bit_buf, 5) - 5);
-entry_1:
- i += tab->run;
- if(i >= 64)
- break; /* end of block */
-normal_code:
- j = scan[i];
- bit_buf <<= tab->len;
- bits += tab->len + 1;
- val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5;
-
- /* if(bitstream_get (1)) val = -val; */
- val = (val ^ SBITS(bit_buf, 1)) - SBITS(bit_buf, 1);
-
- SATURATE(val);
- dest[j] = val;
- mismatch ^= val;
-
- bit_buf <<= 1;
- NEEDBITS;
-
- continue;
- }
-
-entry_2:
- if(bit_buf >= 0x04000000)
- {
- tab = DCT_B14_8 + (UBITS(bit_buf, 8) - 4);
-
- i += tab->run;
- if(i < 64)
- goto normal_code;
-
- /* escape code */
-
- i += UBITS(bit_buf << 6, 6) - 64;
- if(i >= 64)
- break; /* illegal, check needed to avoid buffer overflow */
-
- j = scan[i];
-
- DUMPBITS(12);
- NEEDBITS;
- val = 2 * (SBITS(bit_buf, 12) + SBITS(bit_buf, 1)) + 1;
- val = (val * quantizer_scale * quant_matrix[j]) / 32;
-
- SATURATE(val);
- dest[j] = val;
- mismatch ^= val;
-
- DUMPBITS(12);
- NEEDBITS;
-
- continue;
- }
- else if(bit_buf >= 0x02000000)
- {
- tab = DCT_B14_10 + (UBITS(bit_buf, 10) - 8);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
- else if(bit_buf >= 0x00800000)
- {
- tab = DCT_13 + (UBITS(bit_buf, 13) - 16);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
- else if(bit_buf >= 0x00200000)
- {
- tab = DCT_15 + (UBITS(bit_buf, 15) - 16);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
- else
- {
- tab = DCT_16 + UBITS(bit_buf, 16);
- bit_buf <<= 16;
- GETWORD (bit_buf, bits + 16, bit_ptr);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
-
- break; /* illegal, check needed to avoid buffer overflow */
- }
-
- dest[63] ^= mismatch & 1;
- DUMPBITS(2); /* dump end of block code */
- m_bitstream_buf = bit_buf;
- m_bitstream_bits = bits;
- m_bitstream_ptr = bit_ptr;
-
- return i;
-}
-
-void CMpeg2Decoder::get_mpeg1_intra_block()
-{
- int i, j;
- int val;
- const uint8_t* scan = m_scan;
- const uint8_t* quant_matrix = m_intra_quantizer_matrix;
- int quantizer_scale = m_quantizer_scale;
- const DCTtab* tab;
- uint32_t bit_buf;
- int bits;
- const uint8_t* bit_ptr;
- int16_t* dest;
-
- i = 0;
- dest = m_DCTblock;
-
- bit_buf = m_bitstream_buf;
- bits = m_bitstream_bits;
- bit_ptr = m_bitstream_ptr;
-
- NEEDBITS;
-
- while(1)
- {
- if(bit_buf >= 0x28000000)
- {
- tab = DCT_B14AC_5 + (UBITS(bit_buf, 5) - 5);
-
- i += tab->run;
- if(i >= 64)
- break; /* end of block */
-normal_code:
- j = scan[i];
- bit_buf <<= tab->len;
- bits += tab->len + 1;
- val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4;
-
- /* oddification */
- val = (val - 1) | 1;
-
- /* if(bitstream_get (1)) val = -val; */
- val = (val ^ SBITS(bit_buf, 1)) - SBITS(bit_buf, 1);
-
- SATURATE(val);
- dest[j] = val;
-
- bit_buf <<= 1;
- NEEDBITS;
-
- continue;
- }
- else if(bit_buf >= 0x04000000)
- {
- tab = DCT_B14_8 + (UBITS(bit_buf, 8) - 4);
-
- i += tab->run;
- if(i < 64)
- goto normal_code;
-
- /* escape code */
-
- i += UBITS(bit_buf << 6, 6) - 64;
- if(i >= 64)
- break; /* illegal, check needed to avoid buffer overflow */
-
- j = scan[i];
-
- DUMPBITS(12);
- NEEDBITS;
- val = SBITS(bit_buf, 8);
- if(!(val & 0x7f))
- {
- DUMPBITS(8);
- val = UBITS(bit_buf, 8) + 2 * val;
- }
- val = (val * quantizer_scale * quant_matrix[j]) / 16;
-
- /* oddification */
- val = (val + ~SBITS(val, 1)) | 1;
-
- SATURATE(val);
- dest[j] = val;
-
- DUMPBITS(8);
- NEEDBITS;
-
- continue;
- }
- else if(bit_buf >= 0x02000000)
- {
- tab = DCT_B14_10 + (UBITS(bit_buf, 10) - 8);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
- else if(bit_buf >= 0x00800000)
- {
- tab = DCT_13 + (UBITS(bit_buf, 13) - 16);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
- else if(bit_buf >= 0x00200000)
- {
- tab = DCT_15 + (UBITS(bit_buf, 15) - 16);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
- else
- {
- tab = DCT_16 + UBITS(bit_buf, 16);
- bit_buf <<= 16;
- GETWORD(bit_buf, bits + 16, bit_ptr);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
-
- break; /* illegal, check needed to avoid buffer overflow */
- }
-
- DUMPBITS(2); /* dump end of block code */
- m_bitstream_buf = bit_buf;
- m_bitstream_bits = bits;
- m_bitstream_ptr = bit_ptr;
-}
-
-int CMpeg2Decoder::get_mpeg1_non_intra_block()
-{
- int i, j;
- int val;
- const uint8_t* scan = m_scan;
- const uint8_t* quant_matrix = m_non_intra_quantizer_matrix;
- int quantizer_scale = m_quantizer_scale;
- const DCTtab* tab;
- uint32_t bit_buf;
- int bits;
- const uint8_t* bit_ptr;
- int16_t* dest;
-
- i = -1;
- dest = m_DCTblock;
-
- bit_buf = m_bitstream_buf;
- bits = m_bitstream_bits;
- bit_ptr = m_bitstream_ptr;
-
- NEEDBITS;
- if(bit_buf >= 0x28000000)
- {
- tab = DCT_B14DC_5 + (UBITS(bit_buf, 5) - 5);
- goto entry_1;
- }
- else
- {
- goto entry_2;
- }
-
- while(1)
- {
- if(bit_buf >= 0x28000000)
- {
- tab = DCT_B14AC_5 + (UBITS(bit_buf, 5) - 5);
-entry_1:
- i += tab->run;
- if(i >= 64)
- break; /* end of block */
-normal_code:
- j = scan[i];
- bit_buf <<= tab->len;
- bits += tab->len + 1;
- val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5;
-
- /* oddification */
- val = (val - 1) | 1;
-
- /* if(bitstream_get (1)) val = -val; */
- val = (val ^ SBITS(bit_buf, 1)) - SBITS(bit_buf, 1);
-
- SATURATE(val);
- dest[j] = val;
-
- bit_buf <<= 1;
- NEEDBITS;
-
- continue;
- }
-
-entry_2:
- if(bit_buf >= 0x04000000)
- {
- tab = DCT_B14_8 + (UBITS(bit_buf, 8) - 4);
-
- i += tab->run;
- if(i < 64)
- goto normal_code;
-
- /* escape code */
-
- i += UBITS(bit_buf << 6, 6) - 64;
- if(i >= 64)
- break; /* illegal, check needed to avoid buffer overflow */
-
- j = scan[i];
-
- DUMPBITS(12);
- NEEDBITS;
- val = SBITS(bit_buf, 8);
- if(!(val & 0x7f))
- {
- DUMPBITS(8);
- val = UBITS(bit_buf, 8) + 2 * val;
- }
- val = 2 * (val + SBITS(val, 1)) + 1;
- val = (val * quantizer_scale * quant_matrix[j]) / 32;
-
- /* oddification */
- val = (val + ~SBITS(val, 1)) | 1;
-
- SATURATE(val);
- dest[j] = val;
-
- DUMPBITS(8);
- NEEDBITS;
-
- continue;
- }
- else if(bit_buf >= 0x02000000)
- {
- tab = DCT_B14_10 + (UBITS(bit_buf, 10) - 8);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
- else if(bit_buf >= 0x00800000)
- {
- tab = DCT_13 + (UBITS(bit_buf, 13) - 16);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
- else if(bit_buf >= 0x00200000)
- {
- tab = DCT_15 + (UBITS(bit_buf, 15) - 16);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
- else
- {
- tab = DCT_16 + UBITS(bit_buf, 16);
- bit_buf <<= 16;
- GETWORD (bit_buf, bits + 16, bit_ptr);
- i += tab->run;
- if(i < 64)
- goto normal_code;
- }
-
- break; /* illegal, check needed to avoid buffer overflow */
- }
-
- DUMPBITS(2); /* dump end of block code */
- m_bitstream_buf = bit_buf;
- m_bitstream_bits = bits;
- m_bitstream_ptr = bit_ptr;
-
- return i;
-}
-
-#define bit_buf (m_bitstream_buf)
-#define bits (m_bitstream_bits)
-#define bit_ptr (m_bitstream_ptr)
-
-void CMpeg2Decoder::slice_intra_DCT(const int cc, uint8_t* dest, int stride)
-{
- NEEDBITS;
-
- /* Get the intra DC coefficient and inverse quantize it */
- m_dc_dct_pred[cc] += (cc == 0)
- ? get_luma_dc_dct_diff()
- : get_chroma_dc_dct_diff();
-
- m_DCTblock[0] = m_dc_dct_pred[cc] << (3 - m_intra_dc_precision);
-
- if(m_mpeg1)
- {
- if(m_coding_type != D_TYPE)
- get_mpeg1_intra_block();
- }
- else if(m_intra_vlc_format)
- {
- get_intra_block_B15();
- }
- else
- {
- get_intra_block_B14();
- }
-
- m_idct_copy(m_DCTblock, dest, stride);
-}
-
-void CMpeg2Decoder::slice_non_intra_DCT(uint8_t* dest, int stride)
-{
- int last = m_mpeg1
- ? get_mpeg1_non_intra_block()
- : get_non_intra_block ();
-
- m_idct_add(last, m_DCTblock, dest, stride);
-}
-
-void CMpeg2Decoder::MOTION(
- mpeg2_mc_fct * const * const table, uint8_t** ref,
- int motion_x, int motion_y,
- unsigned int size, unsigned int y, unsigned int limit_y)
-{
- unsigned int pos_x, pos_y, xy_half, offset, dest_offset;
-
- pos_x = 2 * m_offset + motion_x;
- pos_y = 2 * m_v_offset + motion_y + 2 * y;
-
- if(pos_x > m_limit_x)
- {
- pos_x = ((int)pos_x < 0) ? 0 : m_limit_x;
- motion_x = pos_x - 2 * m_offset;
- }
-
- if(pos_y > limit_y)
- {
- pos_y = ((int)pos_y < 0) ? 0 : limit_y;
- motion_y = pos_y - 2 * m_v_offset - 2 * y;
- }
-
- xy_half = ((pos_y & 1) << 1) | (pos_x & 1);
- offset = (pos_x >> 1) + (pos_y >> 1) * m_stride;
- table[xy_half] (m_dest[0] + y * m_stride + m_offset, ref[0] + offset, m_stride, size);
-
- motion_x /= 2; motion_y /= 2;
-
- xy_half = ((motion_y & 1) << 1) | (motion_x & 1);
- offset = ((m_offset + motion_x) >> 1) + ((((m_v_offset + motion_y) >> 1) + y/2) * m_uv_stride);
- dest_offset = y/2 * m_uv_stride + (m_offset >> 1);
- table[4+xy_half] (m_dest[1] + dest_offset, ref[1] + offset, m_uv_stride, size/2);
- table[4+xy_half] (m_dest[2] + dest_offset, ref[2] + offset, m_uv_stride, size/2);
-}
-
-void CMpeg2Decoder::MOTION_FIELD(
- mpeg2_mc_fct * const * const table, uint8_t** ref,
- int motion_x, int motion_y,
- int dest_field, int src_field, unsigned int op)
-{
- unsigned int pos_x, pos_y, xy_half, offset, dest_offset;
-
- pos_x = 2 * m_offset + motion_x;
- pos_y = m_v_offset + motion_y;
-
- if(pos_x > m_limit_x)
- {
- pos_x = ((int)pos_x < 0) ? 0 : m_limit_x;
- motion_x = pos_x - 2 * m_offset;
- }
-
- if(pos_y > m_limit_y)
- {
- pos_y = ((int)pos_y < 0) ? 0 : m_limit_y;
- motion_y = pos_y - m_v_offset;
- }
-
- xy_half = ((pos_y & 1) << 1) | (pos_x & 1);
- offset = (pos_x >> 1) + ((op ? (pos_y | 1) : (pos_y & ~1)) + src_field) * m_stride;
- table[xy_half] (m_dest[0] + dest_field * m_stride + m_offset, ref[0] + offset, 2 * m_stride, 8);
-
- motion_x /= 2; motion_y /= 2;
-
- xy_half = ((motion_y & 1) << 1) | (motion_x & 1);
- offset = ((m_offset + motion_x) >> 1) + (((m_v_offset >> 1) + (op ? (motion_y | 1) :(motion_y & ~1)) + src_field) * m_uv_stride);
- dest_offset = dest_field * m_uv_stride + (m_offset >> 1);
- table[4+xy_half] (m_dest[1] + dest_offset, ref[1] + offset, 2 * m_uv_stride, 4);
- table[4+xy_half] (m_dest[2] + dest_offset, ref[2] + offset, 2 * m_uv_stride, 4);
-}
-
-void CMpeg2Decoder::motion_mp1(motion_t* motion, mpeg2_mc_fct * const * const table)
-{
- int motion_x, motion_y;
-
- NEEDBITS;
- motion_x = motion->pmv[0][0] + (get_motion_delta(motion->f_code[0]) << motion->f_code[1]);
- motion_x = bound_motion_vector(motion_x, motion->f_code[0] + motion->f_code[1]);
- motion->pmv[0][0] = motion_x;
-
- NEEDBITS;
- motion_y = motion->pmv[0][1] + (get_motion_delta(motion->f_code[0]) << motion->f_code[1]);
- motion_y = bound_motion_vector(motion_y, motion->f_code[0] + motion->f_code[1]);
- motion->pmv[0][1] = motion_y;
-
- MOTION(table, motion->ref[0], motion_x, motion_y, 16, 0, m_limit_y_16);
-}
-
-void CMpeg2Decoder::motion_fr_frame(motion_t* motion, mpeg2_mc_fct * const * const table)
-{
- int motion_x, motion_y;
-
- NEEDBITS;
- motion_x = motion->pmv[0][0] + get_motion_delta(motion->f_code[0]);
- motion_x = bound_motion_vector(motion_x, motion->f_code[0]);
- motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
-
- NEEDBITS;
- motion_y = motion->pmv[0][1] + get_motion_delta(motion->f_code[1]);
- motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
- motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
-
- MOTION(table, motion->ref[0], motion_x, motion_y, 16, 0, m_limit_y_16);
-}
-
-void CMpeg2Decoder::motion_fr_field(motion_t* motion, mpeg2_mc_fct * const * const table)
-{
- int motion_x, motion_y, field;
-
- NEEDBITS;
- field = UBITS(bit_buf, 1);
- DUMPBITS(1);
-
- motion_x = motion->pmv[0][0] + get_motion_delta(motion->f_code[0]);
- motion_x = bound_motion_vector(motion_x, motion->f_code[0]);
- motion->pmv[0][0] = motion_x;
-
- NEEDBITS;
- motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta(motion->f_code[1]);
- /* motion_y = bound_motion_vector(motion_y, motion->f_code[1]); */
- motion->pmv[0][1] = motion_y << 1;
-
- MOTION_FIELD(table, motion->ref[0], motion_x, motion_y, 0, field, 0);
-
- NEEDBITS;
- field = UBITS(bit_buf, 1);
- DUMPBITS(1);
-
- motion_x = motion->pmv[1][0] + get_motion_delta(motion->f_code[0]);
- motion_x = bound_motion_vector(motion_x, motion->f_code[0]);
- motion->pmv[1][0] = motion_x;
-
- NEEDBITS;
- motion_y = (motion->pmv[1][1] >> 1) + get_motion_delta(motion->f_code[1]);
- /* motion_y = bound_motion_vector(motion_y, motion->f_code[1]); */
- motion->pmv[1][1] = motion_y << 1;
-
- MOTION_FIELD(table, motion->ref[0], motion_x, motion_y, 1, field, 0);
-}
-
-void CMpeg2Decoder::motion_fr_dmv(motion_t* motion, mpeg2_mc_fct * const * const table)
-{
- int motion_x, motion_y, dmv_x, dmv_y, m, other_x, other_y;
-
- NEEDBITS;
- motion_x = motion->pmv[0][0] + get_motion_delta(motion->f_code[0]);
- motion_x = bound_motion_vector(motion_x, motion->f_code[0]);
- motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
- NEEDBITS;
- dmv_x = get_dmv();
-
- motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta(motion->f_code[1]);
- /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
- motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1;
- dmv_y = get_dmv();
-
- m = m_top_field_first ? 1 : 3;
- other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x;
- other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1;
- MOTION_FIELD(m_mc->put, motion->ref[0], other_x, other_y, 0, 0, 1);
-
- m = m_top_field_first ? 3 : 1;
- other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x;
- other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1;
- MOTION_FIELD(m_mc->put, motion->ref[0], other_x, other_y, 1, 0, 0);
-
- unsigned int pos_x, pos_y, xy_half, offset;
-
- pos_x = 2 * m_offset + motion_x;
- pos_y = m_v_offset + motion_y;
- if(pos_x > m_limit_x)
- {
- pos_x = ((int)pos_x < 0) ? 0 : m_limit_x;
- motion_x = pos_x - 2 * m_offset;
- }
- if(pos_y > m_limit_y)
- {
- pos_y = ((int)pos_y < 0) ? 0 : m_limit_y;
- motion_y = pos_y - m_v_offset;
- }
-
- xy_half = ((pos_y & 1) << 1) | (pos_x & 1);
- offset = (pos_x >> 1) + (pos_y & ~1) * m_stride;
- m_mc->avg[xy_half](m_dest[0] + m_offset, motion->ref[0][0] + offset, 2 * m_stride, 8);
- m_mc->avg[xy_half](m_dest[0] + m_stride + m_offset, motion->ref[0][0] + m_stride + offset, 2 * m_stride, 8);
- motion_x /= 2;
- motion_y /= 2;
- xy_half = ((motion_y & 1) << 1) | (motion_x & 1);
- offset = ((m_offset + motion_x) >> 1) + ((m_v_offset >> 1) + (motion_y & ~1)) * m_uv_stride;
- m_mc->avg[4+xy_half](m_dest[1] + (m_offset >> 1), motion->ref[0][1] + offset, 2 * m_uv_stride, 4);
- m_mc->avg[4+xy_half](m_dest[1] + m_uv_stride + (m_offset >> 1), motion->ref[0][1] + m_uv_stride + offset, 2 * m_uv_stride, 4);
- m_mc->avg[4+xy_half](m_dest[2] + (m_offset >> 1), motion->ref[0][2] + offset, 2 * m_uv_stride, 4);
- m_mc->avg[4+xy_half](m_dest[2] + m_uv_stride + (m_offset >> 1), motion->ref[0][2] + m_uv_stride + offset, 2 * m_uv_stride, 4);
-}
-
-void CMpeg2Decoder::motion_reuse(motion_t* motion, mpeg2_mc_fct * const * const table)
-{
- int motion_x, motion_y;
-
- motion_x = motion->pmv[0][0];
- motion_y = motion->pmv[0][1];
-
- MOTION(table, motion->ref[0], motion_x, motion_y, 16, 0, m_limit_y_16);
-}
-
-void CMpeg2Decoder::motion_zero(motion_t* motion, mpeg2_mc_fct * const * const table)
-{
- unsigned int offset;
-
- table[0](m_dest[0] + m_offset, motion->ref[0][0] + m_offset + m_v_offset * m_stride, m_stride, 16);
- offset = (m_offset >> 1) + (m_v_offset >> 1) * m_uv_stride;
- table[4](m_dest[1] + (m_offset >> 1), motion->ref[0][1] + offset, m_uv_stride, 8);
- table[4](m_dest[2] + (m_offset >> 1), motion->ref[0][2] + offset, m_uv_stride, 8);
-}
-
-/* like motion_frame, but parsing without actual motion compensation */
-void CMpeg2Decoder::motion_fr_conceal()
-{
- int tmp;
-
- NEEDBITS;
- tmp = (m_f_motion.pmv[0][0] + get_motion_delta(m_f_motion.f_code[0]));
- tmp = bound_motion_vector(tmp, m_f_motion.f_code[0]);
- m_f_motion.pmv[1][0] = m_f_motion.pmv[0][0] = tmp;
-
- NEEDBITS;
- tmp = m_f_motion.pmv[0][1] + get_motion_delta(m_f_motion.f_code[1]);
- tmp = bound_motion_vector(tmp, m_f_motion.f_code[1]);
- m_f_motion.pmv[1][1] = m_f_motion.pmv[0][1] = tmp;
-
- DUMPBITS(1); /* remove marker_bit */
-}
-
-void CMpeg2Decoder::motion_fi_field(motion_t * motion, mpeg2_mc_fct * const * const table)
-{
- int motion_x, motion_y;
- uint8_t** ref_field;
-
- NEEDBITS;
- ref_field = motion->ref2[UBITS(bit_buf, 1)];
- DUMPBITS(1);
-
- motion_x = motion->pmv[0][0] + get_motion_delta(motion->f_code[0]);
- motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
- motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
-
- NEEDBITS;
- motion_y = motion->pmv[0][1] + get_motion_delta(motion->f_code[1]);
- motion_y = bound_motion_vector(motion_y, motion->f_code[1]);
- motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
-
- MOTION(table, ref_field, motion_x, motion_y, 16, 0, m_limit_y_16);
-}
-
-void CMpeg2Decoder::motion_fi_16x8(motion_t* motion, mpeg2_mc_fct * const * const table)
-{
- int motion_x, motion_y;
- uint8_t** ref_field;
-
- NEEDBITS;
- ref_field = motion->ref2[UBITS(bit_buf, 1)];
- DUMPBITS(1);
-
- motion_x = motion->pmv[0][0] + get_motion_delta(motion->f_code[0]);
- motion_x = bound_motion_vector(motion_x, motion->f_code[0]);
- motion->pmv[0][0] = motion_x;
-
- NEEDBITS;
- motion_y = motion->pmv[0][1] + get_motion_delta(motion->f_code[1]);
- motion_y = bound_motion_vector(motion_y, motion->f_code[1]);
- motion->pmv[0][1] = motion_y;
-
- MOTION(table, ref_field, motion_x, motion_y, 8, 0, m_limit_y_8);
-
- NEEDBITS;
- ref_field = motion->ref2[UBITS(bit_buf, 1)];
- DUMPBITS(1);
-
- motion_x = motion->pmv[1][0] + get_motion_delta(motion->f_code[0]);
- motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
- motion->pmv[1][0] = motion_x;
-
- NEEDBITS;
- motion_y = motion->pmv[1][1] + get_motion_delta(motion->f_code[1]);
- motion_y = bound_motion_vector(motion_y, motion->f_code[1]);
- motion->pmv[1][1] = motion_y;
-
- MOTION(table, ref_field, motion_x, motion_y, 8, 8, m_limit_y_8);
-}
-
-void CMpeg2Decoder::motion_fi_dmv(motion_t* motion, mpeg2_mc_fct * const * const table)
-{
- int motion_x, motion_y, other_x, other_y;
-
- NEEDBITS;
- motion_x = motion->pmv[0][0] + get_motion_delta(motion->f_code[0]);
- motion_x = bound_motion_vector(motion_x, motion->f_code[0]);
- motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
- NEEDBITS;
- other_x = ((motion_x + (motion_x > 0)) >> 1) + get_dmv();
-
- motion_y = motion->pmv[0][1] + get_motion_delta(motion->f_code[1]);
- motion_y = bound_motion_vector(motion_y, motion->f_code[1]);
- motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
- other_y = ((motion_y + (motion_y > 0)) >> 1) + get_dmv () + m_dmv_offset;
-
- MOTION(m_mc->put, motion->ref[0], motion_x, motion_y, 16, 0, m_limit_y_16);
- MOTION(m_mc->avg, motion->ref[1], other_x, other_y, 16, 0, m_limit_y_16);
-}
-
-void CMpeg2Decoder::motion_fi_conceal()
-{
- int tmp;
-
- NEEDBITS;
- DUMPBITS(1); /* remove field_select */
-
- tmp = m_f_motion.pmv[0][0] + get_motion_delta (m_f_motion.f_code[0]);
- tmp = bound_motion_vector(tmp, m_f_motion.f_code[0]);
- m_f_motion.pmv[1][0] = m_f_motion.pmv[0][0] = tmp;
-
- NEEDBITS;
- tmp = m_f_motion.pmv[0][1] + get_motion_delta(m_f_motion.f_code[1]);
- tmp = bound_motion_vector(tmp, m_f_motion.f_code[1]);
- m_f_motion.pmv[1][1] = m_f_motion.pmv[0][1] = tmp;
-
- DUMPBITS(1); /* remove marker_bit */
-}
-
-#define MOTION_CALL(routine, direction) \
-do { \
- if((direction) & MACROBLOCK_MOTION_FORWARD) \
- routine(&m_f_motion, m_mc->put); \
- if((direction) & MACROBLOCK_MOTION_BACKWARD) \
- routine(&m_b_motion, (direction & MACROBLOCK_MOTION_FORWARD) ? m_mc->avg : m_mc->put); \
-} while (0)
-
-#define NEXT_MACROBLOCK \
-do { \
- m_offset += 16; \
- if(m_offset == m_width) { \
- m_dest[0] += 16 * m_stride; \
- m_dest[1] += 4 * m_stride; \
- m_dest[2] += 4 * m_stride; \
- m_v_offset += 16; \
- if(m_v_offset > m_limit_y) \
- return; \
- m_offset = 0; \
- } \
-} while (0)
-
-void CMpeg2Decoder::mpeg2_init_fbuf(uint8_t* current_fbuf[3], uint8_t* forward_fbuf[3], uint8_t* backward_fbuf[3])
-{
- int offset, stride, height, bottom_field;
-
- stride = m_width;
- bottom_field = (m_picture_structure == BOTTOM_FIELD);
- offset = bottom_field ? stride : 0;
- height = m_height;
-
- m_picture_dest[0] = current_fbuf[0] + offset;
- m_picture_dest[1] = current_fbuf[1] + (offset >> 1);
- m_picture_dest[2] = current_fbuf[2] + (offset >> 1);
-
- m_f_motion.ref[0][0] = forward_fbuf[0] + offset;
- m_f_motion.ref[0][1] = forward_fbuf[1] + (offset >> 1);
- m_f_motion.ref[0][2] = forward_fbuf[2] + (offset >> 1);
-
- m_b_motion.ref[0][0] = backward_fbuf[0] + offset;
- m_b_motion.ref[0][1] = backward_fbuf[1] + (offset >> 1);
- m_b_motion.ref[0][2] = backward_fbuf[2] + (offset >> 1);
-
- if(m_picture_structure != FRAME_PICTURE)
- {
- m_dmv_offset = bottom_field ? 1 : -1;
- m_f_motion.ref2[0] = m_f_motion.ref[bottom_field];
- m_f_motion.ref2[1] = m_f_motion.ref[!bottom_field];
- m_b_motion.ref2[0] = m_b_motion.ref[bottom_field];
- m_b_motion.ref2[1] = m_b_motion.ref[!bottom_field];
- offset = stride - offset;
-
- if(m_second_field && (m_coding_type != B_TYPE))
- forward_fbuf = current_fbuf;
-
- m_f_motion.ref[1][0] = forward_fbuf[0] + offset;
- m_f_motion.ref[1][1] = forward_fbuf[1] + (offset >> 1);
- m_f_motion.ref[1][2] = forward_fbuf[2] + (offset >> 1);
-
- m_b_motion.ref[1][0] = backward_fbuf[0] + offset;
- m_b_motion.ref[1][1] = backward_fbuf[1] + (offset >> 1);
- m_b_motion.ref[1][2] = backward_fbuf[2] + (offset >> 1);
-
- stride <<= 1;
- height >>= 1;
- }
-
- m_stride = stride;
- m_uv_stride = stride >> 1;
- m_limit_x = 2 * m_width - 32;
- m_limit_y_16 = 2 * height - 32;
- m_limit_y_8 = 2 * height - 16;
- m_limit_y = height - 16;
-}
-
-int CMpeg2Decoder::slice_init(int code)
-{
- int offset;
- const MBAtab* mba;
-
- m_dc_dct_pred[0] = m_dc_dct_pred[1] =
- m_dc_dct_pred[2] = 128 << m_intra_dc_precision;
-
- m_f_motion.pmv[0][0] = m_f_motion.pmv[0][1] = 0;
- m_f_motion.pmv[1][0] = m_f_motion.pmv[1][1] = 0;
- m_b_motion.pmv[0][0] = m_b_motion.pmv[0][1] = 0;
- m_b_motion.pmv[1][0] = m_b_motion.pmv[1][1] = 0;
-
- if(m_vertical_position_extension)
- {
- code += UBITS(bit_buf, 3) << 7;
- DUMPBITS(3);
- }
-
- m_v_offset = (code - 1) * 16;
- offset = (code - 1) * m_stride * 4;
-
- m_dest[0] = m_picture_dest[0] + offset * 4;
- m_dest[1] = m_picture_dest[1] + offset;
- m_dest[2] = m_picture_dest[2] + offset;
-
- m_quantizer_scale = get_quantizer_scale();
-
- /* ignore intra_slice and all the extra data */
- while(bit_buf & 0x80000000)
- {
- DUMPBITS(9);
- NEEDBITS;
- }
-
- /* decode initial macroblock address increment */
- offset = 0;
- while(1)
- {
- if(bit_buf >= 0x08000000)
- {
- mba = MBA_5 + (UBITS(bit_buf, 6) - 2);
- break;
- }
- else if(bit_buf >= 0x01800000)
- {
- mba = MBA_11 + (UBITS(bit_buf, 12) - 24);
- break;
- }
- else
- {
- switch(UBITS(bit_buf, 12))
- {
- case 8: /* macroblock_escape */
- offset += 33;
- DUMPBITS(11);
- NEEDBITS;
- continue;
- case 15: /* macroblock_stuffing (MPEG1 only) */
- bit_buf &= 0xfffff;
- DUMPBITS(11);
- NEEDBITS;
- continue;
- default: /* error */
- return 1;
- }
- }
- }
-
- DUMPBITS(mba->len + 1);
- m_offset = (offset + mba->mba) << 4;
-
- while(m_offset - m_width >= 0)
- {
- m_offset -= m_width;
- m_dest[0] += 16 * m_stride;
- m_dest[1] += 4 * m_stride;
- m_dest[2] += 4 * m_stride;
- m_v_offset += 16;
- }
-
- if(m_v_offset > m_limit_y)
- return 1;
-
- return 0;
-}
-
-void CMpeg2Decoder::mpeg2_slice(int code, const uint8_t* buffer)
-{
- m_bitstream_buf = (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
- m_bitstream_ptr = buffer + 4;
- m_bitstream_bits = -16;
-
- if(slice_init(code))
- return;
-
- while(1)
- {
- int macroblock_modes;
- int mba_inc;
- const MBAtab * mba;
-
- NEEDBITS;
-
- macroblock_modes = get_macroblock_modes();
-
- /* maybe integrate MACROBLOCK_QUANT test into get_macroblock_modes ? */
- if(macroblock_modes & MACROBLOCK_QUANT)
- m_quantizer_scale = get_quantizer_scale();
-
- if(macroblock_modes & MACROBLOCK_INTRA)
- {
- int DCT_offset, DCT_stride;
- int offset;
- uint8_t* dest_y;
-
- if(m_concealment_motion_vectors)
- {
- if(m_picture_structure == FRAME_PICTURE) motion_fr_conceal();
- else motion_fi_conceal();
- }
- else
- {
- m_f_motion.pmv[0][0] = m_f_motion.pmv[0][1] = 0;
- m_f_motion.pmv[1][0] = m_f_motion.pmv[1][1] = 0;
- m_b_motion.pmv[0][0] = m_b_motion.pmv[0][1] = 0;
- m_b_motion.pmv[1][0] = m_b_motion.pmv[1][1] = 0;
- }
-
- if(macroblock_modes & DCT_TYPE_INTERLACED)
- {
- DCT_offset = m_stride;
- DCT_stride = m_stride * 2;
- }
- else
- {
- DCT_offset = m_stride * 8;
- DCT_stride = m_stride;
- }
-
- offset = m_offset;
- dest_y = m_dest[0] + offset;
- slice_intra_DCT(0, dest_y, DCT_stride);
- slice_intra_DCT(0, dest_y + 8, DCT_stride);
- slice_intra_DCT(0, dest_y + DCT_offset, DCT_stride);
- slice_intra_DCT(0, dest_y + DCT_offset + 8, DCT_stride);
- slice_intra_DCT(1, m_dest[1] + (offset >> 1), m_uv_stride);
- slice_intra_DCT (2, m_dest[2] + (offset >> 1), m_uv_stride);
-
- if(m_coding_type == D_TYPE)
- {
- NEEDBITS;
- DUMPBITS(1);
- }
- }
- else
- {
- if(m_picture_structure == FRAME_PICTURE)
- {
- switch((macroblock_modes >> 6) & 3) // macroblock_modes & MOTION_TYPE_MASK
- {
- case 0:
- // non-intra mb without forward mv in a P picture //
- m_f_motion.pmv[0][0] = 0;
- m_f_motion.pmv[0][1] = 0;
- m_f_motion.pmv[1][0] = 0;
- m_f_motion.pmv[1][1] = 0;
- MOTION_CALL(motion_zero, MACROBLOCK_MOTION_FORWARD);
- break;
-
- case 1: // MC_FIELD:
- MOTION_CALL(motion_fr_field, macroblock_modes);
- break;
-
- case 2: // MC_FRAME:
-
- if(m_mpeg1) MOTION_CALL(motion_mp1, macroblock_modes);
- else MOTION_CALL (motion_fr_frame, macroblock_modes);
- break;
-
- case 3: // MC_DMV:
- MOTION_CALL(motion_fr_dmv, MACROBLOCK_MOTION_FORWARD);
- break;
-
- default:
- __assume(0);
- }
- }
- else
- {
- switch((macroblock_modes >> 6) & 3) // macroblock_modes & MOTION_TYPE_MASK
- {
- case 0:
- /* non-intra mb without forward mv in a P picture */
- m_f_motion.pmv[0][0] = 0;
- m_f_motion.pmv[0][1] = 0;
- m_f_motion.pmv[1][0] = 0;
- m_f_motion.pmv[1][1] = 0;
- MOTION_CALL(motion_zero, MACROBLOCK_MOTION_FORWARD);
- break;
-
- case 1: // MC_FIELD
- MOTION_CALL(motion_fi_field, macroblock_modes);
- break;
-
- case 2: // MC_16X8
- MOTION_CALL(motion_fi_16x8, macroblock_modes);
- break;
-
- case 3: // MC_DMV
- MOTION_CALL(motion_fi_dmv, MACROBLOCK_MOTION_FORWARD);
- break;
-
- default:
- __assume(0);
- }
- }
-
- if(macroblock_modes & MACROBLOCK_PATTERN)
- {
- int coded_block_pattern;
- int DCT_offset, DCT_stride;
- int offset;
- uint8_t* dest_y;
-
- if(macroblock_modes & DCT_TYPE_INTERLACED)
- {
- DCT_offset = m_stride;
- DCT_stride = m_stride * 2;
- }
- else
- {
- DCT_offset = m_stride * 8;
- DCT_stride = m_stride;
- }
-
- coded_block_pattern = get_coded_block_pattern();
-
- offset = m_offset;
- dest_y = m_dest[0] + offset;
-
- if(coded_block_pattern & 0x20)
- slice_non_intra_DCT(dest_y, DCT_stride);
- if(coded_block_pattern & 0x10)
- slice_non_intra_DCT(dest_y + 8, DCT_stride);
- if(coded_block_pattern & 0x08)
- slice_non_intra_DCT(dest_y + DCT_offset, DCT_stride);
- if(coded_block_pattern & 0x04)
- slice_non_intra_DCT(dest_y + DCT_offset + 8, DCT_stride);
- if(coded_block_pattern & 0x2)
- slice_non_intra_DCT(m_dest[1] + (offset >> 1), m_uv_stride);
- if(coded_block_pattern & 0x1)
- slice_non_intra_DCT(m_dest[2] + (offset >> 1), m_uv_stride);
- }
-
- m_dc_dct_pred[0] =
- m_dc_dct_pred[1] =
- m_dc_dct_pred[2] = 128 << m_intra_dc_precision;
- }
-
- NEXT_MACROBLOCK;
-
- NEEDBITS;
- mba_inc = 0;
- while(1)
- {
- if(bit_buf >= 0x10000000)
- {
- mba = MBA_5 + (UBITS(bit_buf, 5) - 2);
- break;
- }
- else if(bit_buf >= 0x03000000)
- {
- mba = MBA_11 + (UBITS(bit_buf, 11) - 24);
- break;
- }
- else
- {
- switch(UBITS(bit_buf, 11))
- {
- case 8: /* macroblock_escape */
- mba_inc += 33;
- /* pass through */
- case 15: /* macroblock_stuffing (MPEG1 only) */
- DUMPBITS(11);
- NEEDBITS;
- continue;
- default: /* end of slice, or error */
- return;
- }
- }
- }
-
- DUMPBITS(mba->len);
- mba_inc += mba->mba;
-
- if(mba_inc)
- {
- m_dc_dct_pred[0] =
- m_dc_dct_pred[1] =
- m_dc_dct_pred[2] = 128 << m_intra_dc_precision;
-
- if(m_coding_type == P_TYPE)
- {
- m_f_motion.pmv[0][0] = m_f_motion.pmv[0][1] = 0;
- m_f_motion.pmv[1][0] = m_f_motion.pmv[1][1] = 0;
-
- do {
- MOTION_CALL(motion_zero, MACROBLOCK_MOTION_FORWARD);
- NEXT_MACROBLOCK;
- } while(--mba_inc);
- }
- else
- {
- do {
- MOTION_CALL (motion_reuse, macroblock_modes);
- NEXT_MACROBLOCK;
- } while(--mba_inc);
- }
- }
- }
-}
-
-#undef bit_buf
-#undef bits
-#undef bit_ptr
-
-///////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////
-
-CMpeg2Info::CMpeg2Info()
-{
- m_sequence = NULL;
- m_gop = NULL;
- Reset();
-}
-
-CMpeg2Info::~CMpeg2Info()
-{
-}
-
-void CMpeg2Info::Reset()
-{
- m_current_picture = m_current_picture_2nd = NULL;
- m_display_picture = m_display_picture_2nd = NULL;
- m_current_fbuf = m_display_fbuf = m_discard_fbuf = NULL;
- m_user_data = NULL;
- m_user_data_len = 0;
-}
-
-#ifdef _WIN64
-#pragma warning(pop)
-#endif
diff --git a/src/filters/transform/Mpeg2DecFilter/libmpeg2.h b/src/filters/transform/Mpeg2DecFilter/libmpeg2.h
deleted file mode 100644
index 616a73f90..000000000
--- a/src/filters/transform/Mpeg2DecFilter/libmpeg2.h
+++ /dev/null
@@ -1,402 +0,0 @@
-/*
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
- * See http://libmpeg2.sourceforge.net/ for updates.
- *
- * mpeg2dec 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 of the License, or
- * (at your option) any later version.
- *
- * mpeg2dec 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#pragma once
-
-// TODO: remove this when it's fixed in MSVC
-// Work around warning C4005: 'XXXX' : macro redefinition
-#pragma warning(push)
-#pragma warning(disable: 4005)
-#include <stdint.h>
-#pragma warning(pop)
-
-#define MPEG2_VERSION(a,b,c) (((a)<<16)|((b)<<8)|(c))
-#define MPEG2_RELEASE MPEG2_VERSION (0, 3, 2) /* 0.3.2 */
-
-#define SEQ_FLAG_MPEG2 1
-#define SEQ_FLAG_CONSTRAINED_PARAMETERS 2
-#define SEQ_FLAG_PROGRESSIVE_SEQUENCE 4
-#define SEQ_FLAG_LOW_DELAY 8
-#define SEQ_FLAG_COLOUR_DESCRIPTION 16
-
-#define SEQ_MASK_VIDEO_FORMAT 0xe0
-#define SEQ_VIDEO_FORMAT_COMPONENT 0
-#define SEQ_VIDEO_FORMAT_PAL 0x20
-#define SEQ_VIDEO_FORMAT_NTSC 0x40
-#define SEQ_VIDEO_FORMAT_SECAM 0x60
-#define SEQ_VIDEO_FORMAT_MAC 0x80
-#define SEQ_VIDEO_FORMAT_UNSPECIFIED 0xa0
-
-typedef struct {
- unsigned int width, height;
- unsigned int chroma_width, chroma_height;
- unsigned int byte_rate;
- unsigned int vbv_buffer_size;
- uint32_t flags;
-
- unsigned int picture_width, picture_height;
- unsigned int display_width, display_height;
- unsigned int pixel_width, pixel_height;
- unsigned int frame_period;
-
- uint8_t profile_level_id;
- uint8_t colour_primaries;
- uint8_t transfer_characteristics;
- uint8_t matrix_coefficients;
-
- void finalize();
-} mpeg2_sequence_t;
-
-#define GOP_FLAG_DROP_FRAME 1
-#define GOP_FLAG_BROKEN_LINK 2
-#define GOP_FLAG_CLOSED_GOP 4
-
-typedef struct {
- uint8_t hours;
- uint8_t minutes;
- uint8_t seconds;
- uint8_t pictures;
- uint32_t flags;
-} mpeg2_gop_t;
-
-#define PIC_MASK_CODING_TYPE 7
-#define PIC_FLAG_CODING_TYPE_I 1
-#define PIC_FLAG_CODING_TYPE_P 2
-#define PIC_FLAG_CODING_TYPE_B 3
-#define PIC_FLAG_CODING_TYPE_D 4
-
-#define PIC_FLAG_TOP_FIELD_FIRST 8
-#define PIC_FLAG_PROGRESSIVE_FRAME 16
-#define PIC_FLAG_COMPOSITE_DISPLAY 32
-#define PIC_FLAG_SKIP 64
-#define PIC_FLAG_PTS 128
-#define PIC_FLAG_REPEAT_FIRST_FIELD 256
-#define PIC_MASK_COMPOSITE_DISPLAY 0xfffff000
-
-typedef struct {
- unsigned int temporal_reference;
- unsigned int nb_fields;
- uint32_t pts;
- uint32_t flags;
- struct {
- int x, y;
- } display_offset[3];
- __int64 rtStart, rtStop;
- bool fDiscontinuity, fDelivered;
-} mpeg2_picture_t;
-
-typedef struct {
- uint8_t* buf[3];
- void* id;
-} mpeg2_fbuf_t;
-
-typedef enum {
- STATE_BUFFER = 0,
- STATE_SEQUENCE = 1,
- STATE_SEQUENCE_REPEATED = 2,
- STATE_GOP = 3,
- STATE_PICTURE = 4,
- STATE_SLICE_1ST = 5,
- STATE_PICTURE_2ND = 6,
- STATE_SLICE = 7,
- STATE_END = 8,
- STATE_INVALID = 9,
- STATE_PADDING = 10
-} mpeg2_state_t;
-
-////////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////////////////////
-
-/* macroblock modes */
-#define MACROBLOCK_INTRA 1
-#define MACROBLOCK_PATTERN 2
-#define MACROBLOCK_MOTION_BACKWARD 4
-#define MACROBLOCK_MOTION_FORWARD 8
-#define MACROBLOCK_QUANT 16
-#define DCT_TYPE_INTERLACED 32
-/* motion_type */
-#define MOTION_TYPE_MASK (3*64)
-#define MOTION_TYPE_BASE 64
-#define MC_FIELD (1*64)
-#define MC_FRAME (2*64)
-#define MC_16X8 (2*64)
-#define MC_DMV (3*64)
-
-/* picture structure */
-#define TOP_FIELD 1
-#define BOTTOM_FIELD 2
-#define FRAME_PICTURE 3
-
-/* picture coding type */
-#define I_TYPE 1
-#define P_TYPE 2
-#define B_TYPE 3
-#define D_TYPE 4
-
-////////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////////////////////
-
-typedef void mpeg2_mc_fct(uint8_t*, const uint8_t*, int, int);
-typedef struct {mpeg2_mc_fct* put[8]; mpeg2_mc_fct* avg[8];} mpeg2_mc_t;
-
-class CMpeg2Decoder
-{
-public:
- /* Motion vectors */
- /* The f_ and b_ correspond to the forward and backward motion */
- /* predictors */
-
- struct motion_t {
- uint8_t* ref[2][3];
- uint8_t** ref2[2];
- int pmv[2][2];
- int f_code[2];
- } m_b_motion, m_f_motion;
-
-private:
- int get_macroblock_modes();
- int get_quantizer_scale();
- int get_motion_delta(const int f_code);
- int bound_motion_vector(const int vector, const int f_code);
- int get_dmv();
- int get_coded_block_pattern();
- int get_luma_dc_dct_diff();
- int get_chroma_dc_dct_diff();
-
- void get_intra_block_B14();
- void get_intra_block_B15();
- int get_non_intra_block();
- void get_mpeg1_intra_block();
- int get_mpeg1_non_intra_block();
- void slice_intra_DCT(const int cc, uint8_t* dest, int stride);
- void slice_non_intra_DCT(uint8_t* dest, int stride);
-
- void MOTION(mpeg2_mc_fct * const * const table, uint8_t** ref, int motion_x, int motion_y, unsigned int size, unsigned int y, unsigned int limit_y);
- void MOTION_FIELD(mpeg2_mc_fct * const * const table, uint8_t** ref, int motion_x, int motion_y, int dest_field, int src_field, unsigned int op);
-
- void motion_mp1(motion_t* motion, mpeg2_mc_fct * const * const table);
- void motion_fr_frame(motion_t* motion, mpeg2_mc_fct * const * const table);
- void motion_fr_field(motion_t* motion, mpeg2_mc_fct * const * const table);
- void motion_fr_dmv(motion_t* motion, mpeg2_mc_fct * const * const table);
- void motion_reuse(motion_t* motion, mpeg2_mc_fct * const * const table);
- void motion_zero(motion_t* motion, mpeg2_mc_fct * const * const table);
- void motion_fr_conceal();
- void motion_fi_field(motion_t * motion, mpeg2_mc_fct * const * const table);
- void motion_fi_16x8(motion_t* motion, mpeg2_mc_fct * const * const table);
- void motion_fi_dmv(motion_t* motion, mpeg2_mc_fct * const * const table);
- void motion_fi_conceal();
-
- int slice_init(int code);
-
- static bool m_idct_initialized;
- void (*m_idct_init)();
- void (*m_idct_copy)(int16_t* block, uint8_t* dest, const int stride);
- void (*m_idct_add)(const int last, int16_t* block, uint8_t* dest, const int stride);
- mpeg2_mc_t* m_mc;
-
-public:
- CMpeg2Decoder();
- virtual ~CMpeg2Decoder();
-
- void mpeg2_init_fbuf(uint8_t* current_fbuf[3], uint8_t* forward_fbuf[3], uint8_t* backward_fbuf[3]);
- void mpeg2_slice(int code, const uint8_t* buffer);
-
- int16_t* m_DCTblock;
-
- /* bit parsing stuff */
- uint32_t m_bitstream_buf; /* current 32 bit working set */
- int m_bitstream_bits; /* used bits in working set */
- const uint8_t* m_bitstream_ptr; /* buffer with stream data */
-
- uint8_t* m_dest[3];
- uint8_t* m_picture_dest[3];
-
- int m_offset, m_stride, m_uv_stride;
- unsigned int m_limit_x, m_limit_y_16, m_limit_y_8, m_limit_y;
-
- /* predictor for DC coefficients in intra blocks */
- int16_t m_dc_dct_pred[3];
-
- int m_quantizer_scale; /* remove */
- int m_dmv_offset; /* remove */
- unsigned int m_v_offset; /* remove */
-
- /* now non-slice-specific information */
-
- /* sequence header stuff */
- uint8_t m_intra_quantizer_matrix[64];
- uint8_t m_non_intra_quantizer_matrix[64];
-
- /* The width and height of the picture snapped to macroblock units */
- int m_width, m_height;
- int m_vertical_position_extension;
-
- /* picture header stuff */
-
- /* what type of picture this is (I, P, B, D) */
- int m_coding_type;
-
- /* picture coding extension stuff */
-
- /* quantization factor for intra dc coefficients */
- int m_intra_dc_precision;
- /* top/bottom/both fields */
- int m_picture_structure;
- /* bool to indicate all predictions are frame based */
- int m_frame_pred_frame_dct;
- /* bool to indicate whether intra blocks have motion vectors */
- /* (for concealment) */
- int m_concealment_motion_vectors;
- /* bit to indicate which quantization table to use */
- int m_q_scale_type;
- /* bool to use different vlc tables */
- int m_intra_vlc_format;
- /* used for DMV MC */
- int m_top_field_first;
-
- /* stuff derived from bitstream */
-
- /* pointer to the zigzag scan we're supposed to be using */
- const uint8_t* m_scan;
-
- int m_second_field;
-
- int m_mpeg1;
-};
-
-class CMpeg2Info
-{
-public:
- CMpeg2Info();
- virtual ~CMpeg2Info();
-
- void Reset();
-
- mpeg2_sequence_t* m_sequence;
- mpeg2_gop_t* m_gop;
- mpeg2_picture_t* m_current_picture;
- mpeg2_picture_t* m_current_picture_2nd;
- mpeg2_fbuf_t* m_current_fbuf;
- mpeg2_picture_t* m_display_picture;
- mpeg2_picture_t* m_display_picture_2nd;
- mpeg2_fbuf_t* m_display_fbuf;
- mpeg2_fbuf_t* m_discard_fbuf;
- const uint8_t* m_user_data;
- int m_user_data_len;
-};
-
-class CMpeg2Dec
-{
- int skip_chunk(int bytes);
- int copy_chunk(int bytes);
- mpeg2_state_t seek_chunk(), seek_header(), seek_sequence();
-
- int sequence_ext();
- int sequence_display_ext();
- int quant_matrix_ext();
- int copyright_ext();
- int picture_display_ext();
- int picture_coding_ext();
-
-public:
- CMpeg2Dec();
- virtual ~CMpeg2Dec();
-
- void mpeg2_init();
- void mpeg2_close();
-
- void mpeg2_buffer(uint8_t* start, uint8_t* end);
- int mpeg2_getpos();
- mpeg2_state_t mpeg2_parse();
-
- void mpeg2_skip(int skip);
- void mpeg2_slice_region(int start, int end);
-
- void mpeg2_pts(uint32_t pts);
-
- /* decode.c */
- mpeg2_state_t mpeg2_seek_sequence();
- mpeg2_state_t mpeg2_parse_header();
-
- /* header.c */
- void mpeg2_header_state_init();
- int mpeg2_header_sequence();
- int mpeg2_header_gop();
- mpeg2_state_t mpeg2_header_picture_start();
- int mpeg2_header_picture();
- int mpeg2_header_extension();
- int mpeg2_header_user_data();
- void mpeg2_header_matrix_finalize();
- void mpeg2_header_sequence_finalize();
- mpeg2_state_t mpeg2_header_slice_start();
- mpeg2_state_t mpeg2_header_end();
- void mpeg2_set_fbuf(int coding_type);
-
- enum {BUFFER_SIZE = 1194 * 1024};
-
-
- CMpeg2Decoder m_decoder;
- CMpeg2Info m_info;
-
- uint32_t m_shift;
- int m_is_display_initialized;
- mpeg2_state_t (CMpeg2Dec::* m_action)();
- mpeg2_state_t m_state;
- uint32_t m_ext_state;
-
- /* allocated in init - gcc has problems allocating such big structures */
- uint8_t* m_chunk_buffer;
- /* pointer to start of the current chunk */
- uint8_t* m_chunk_start;
- /* pointer to current position in chunk_buffer */
- uint8_t* m_chunk_ptr;
- /* last start code ? */
- uint8_t m_code;
-
- /* PTS */
- uint32_t m_pts_current, m_pts_previous;
- int m_num_pts;
- int m_bytes_since_pts;
-
- bool m_first;
- int m_alloc_index;
- uint8_t m_first_decode_slice;
- uint8_t m_nb_decode_slices;
-
- mpeg2_sequence_t m_new_sequence;
- mpeg2_sequence_t m_sequence;
- mpeg2_gop_t m_gop;
- mpeg2_picture_t m_pictures[4];
- mpeg2_picture_t* m_picture;
- /*const*/ mpeg2_fbuf_t* m_fbuf[3]; /* 0: current fbuf, 1-2: prediction fbufs */
-
- mpeg2_fbuf_t m_fbuf_alloc[3];
-
- uint8_t* m_buf_start;
- uint8_t* m_buf_end;
-
- int16_t m_display_offset_x, m_display_offset_y;
-
- int m_copy_matrix;
- uint8_t m_intra_quantizer_matrix[64];
- uint8_t m_non_intra_quantizer_matrix[64];
-};
diff --git a/src/filters/transform/Mpeg2DecFilter/mc_sse2.cpp b/src/filters/transform/Mpeg2DecFilter/mc_sse2.cpp
deleted file mode 100644
index 57cea4af5..000000000
--- a/src/filters/transform/Mpeg2DecFilter/mc_sse2.cpp
+++ /dev/null
@@ -1,483 +0,0 @@
-/*
- * (C) 2003-2006 Gabest
- * (C) 2006-2012 see Authors.txt
- *
- * This file is part of MPC-HC.
- *
- * MPC-HC 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 3 of the License, or
- * (at your option) any later version.
- *
- * MPC-HC 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 this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-// Based on Intel's AP-942
-
-#include "stdafx.h"
-#include <inttypes.h>
-#include "libmpeg2.h"
-#include "attributes.h"
-#include "../../../DSUtil/simd.h"
-
-static const __m128i const_1_16_bytes = _mm_set1_epi16(1);
-
-static void MC_put_o_16_sse2(uint8_t* ecx, const uint8_t* edx, const int eax, int esi)
-{
- const int edi = eax + eax;
- const int ebx = edi + eax;
- for (; esi; edx += edi * 2, ecx += edi * 2, esi -= 4) {
- __m128i xmm0, xmm1, xmm2, xmm3;
- movdqu(xmm0, edx);
- movdqu(xmm1, edx + eax);
- movdqu(xmm2, edx + edi);
- movdqu(xmm3, edx + ebx);
- movdqa(ecx, xmm0);
- movdqa(ecx + eax, xmm1);
- movdqa(ecx + edi, xmm2);
- movdqa(ecx + ebx, xmm3);
- }
-}
-
-static void MC_put_o_8_sse2(uint8_t* ecx, const uint8_t* edx, const int eax, int esi)
-{
- const int edi = eax + eax;
- const int ebx = edi + eax;
- for (; esi; edx += edi * 2, ecx += edi * 2, esi -= 4) {
- __m128d xmm0, xmm1, xmm2, xmm3;
- movlpd(xmm0, edx);
- movlpd(xmm1, edx + eax);
- movlpd(xmm2, edx + edi);
- movlpd(xmm3, edx + ebx);
- movlpd(ecx, xmm0);
- movlpd(ecx + eax, xmm1);
- movlpd(ecx + edi, xmm2);
- movlpd(ecx + ebx, xmm3);
- }
-}
-
-static void MC_put_x_16_sse2(uint8_t* ecx, const uint8_t* edx, const int eax, int esi)
-{
- const int edi = eax + eax;
- const int ebx = edi + eax;
- for (; esi; edx += edi * 2, ecx += edi * 2, esi -= 4) {
- __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7;
- movdqu(xmm0, edx);
- movdqu(xmm1, edx + 1);
- movdqu(xmm2, edx + eax);
- movdqu(xmm3, edx + eax + 1);
- movdqu(xmm4, edx + edi);
- movdqu(xmm5, edx + edi + 1);
- movdqu(xmm6, edx + ebx);
- movdqu(xmm7, edx + ebx + 1);
- pavgb(xmm0, xmm1);
- pavgb(xmm2, xmm3);
- pavgb(xmm4, xmm5);
- pavgb(xmm6, xmm7);
- movdqa(ecx, xmm0);
- movdqa(ecx + eax, xmm2);
- movdqa(ecx + edi, xmm4);
- movdqa(ecx + ebx, xmm6);
- }
-}
-
-static void MC_put_x_8_sse2(uint8_t* ecx, const uint8_t* edx, const int eax, int esi)
-{
- const int edi = eax + eax;
- const int ebx = edi + eax;
- __m128i xmm0, xmm1, xmm2, xmm3;
- for (; esi; edx += edi * 2, ecx += edi * 2, esi -= 4) {
- movlpd(xmm0, edx);
- movlpd(xmm1, edx + 1);
- movhpd(xmm0, edx + eax);
- movhpd(xmm1, edx + eax + 1);
- movlpd(xmm2, edx + edi);
- movlpd(xmm3, edx + edi + 1);
- movhpd(xmm2, edx + ebx);
- movhpd(xmm3, edx + ebx + 1);
- pavgb(xmm0, xmm1);
- pavgb(xmm2, xmm3);
- movlpd(ecx, xmm0);
- movhpd(ecx + eax, xmm0);
- movlpd(ecx + edi, xmm2);
- movhpd(ecx + ebx, xmm2);
- }
-}
-
-static void MC_put_y_16_sse2(uint8_t* ecx, const uint8_t* edx, const int eax, int esi)
-{
- const int edi = eax + eax;
- const int ebx = edi + eax;
- __m128i xmm0;
- movdqu(xmm0, edx);
- for (; esi; edx += edi * 2, ecx += edi * 2, esi -= 4) {
- __m128i xmm1, xmm2, xmm3, xmm4;
- movdqu(xmm1, edx + eax);
- movdqu(xmm2, edx + edi);
- movdqu(xmm3, edx + ebx);
- movdqu(xmm4, edx + edi * 2);
- pavgb(xmm0, xmm1);
- pavgb(xmm1, xmm2);
- pavgb(xmm2, xmm3);
- pavgb(xmm3, xmm4);
- movdqa(ecx, xmm0);
- movdqa(ecx + eax, xmm1);
- movdqa(ecx + edi, xmm2);
- movdqa(ecx + ebx, xmm3);
- movdqa(xmm0, xmm4);
- }
-}
-
-static void MC_put_y_8_sse2(uint8_t* ecx, const uint8_t* edx, const int eax, int esi)
-{
- const int edi = eax + eax;
- const int ebx = edi + eax;
- __m128i xmm0;
- movlpd(xmm0, edx);
-
- for (; esi; edx += edi * 2, ecx += edi * 2, esi -= 4) {
- __m128i xmm1, xmm2, xmm3, xmm4;
- movlpd(xmm1, edx + eax);
- movlpd(xmm2, edx + edi);
- movlpd(xmm3, edx + ebx);
- movlpd(xmm4, edx + edi * 2);
- pavgb(xmm0, xmm1);
- pavgb(xmm1, xmm2);
- pavgb(xmm2, xmm3);
- pavgb(xmm3, xmm4);
- movlpd(ecx, xmm0);
- movlpd(ecx + eax, xmm1);
- movlpd(ecx + edi, xmm2);
- movlpd(ecx + ebx, xmm3);
- movdqa(xmm0, xmm4);
- }
-}
-
-static void MC_put_xy_16_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
-{
- const uint8_t* edx = ref ;
- uint8_t* ecx = dest;
- int eax = stride;
- int esi = height;
- int edi = eax + eax;
- __m128i xmm7, xmm0, xmm1, xmm4, xmm5, xmm2, xmm3;
- movdqa(xmm7, const_1_16_bytes);
- movdqu(xmm0, edx);
- movdqu(xmm1, edx + 1);
- for (; esi; edx += edi, ecx += edi, esi -= 2) {
- movdqu(xmm2, edx + eax);
- movdqu(xmm3, edx + eax + 1);
- movdqu(xmm4, edx + edi);
- movdqu(xmm5, edx + edi + 1);
- pavgb(xmm0, xmm1);
- pavgb(xmm2, xmm3);
- movdqa(xmm1, xmm5);
- pavgb(xmm5, xmm4);
- psubusb(xmm2, xmm7);
- pavgb(xmm0, xmm2);
- pavgb(xmm2, xmm5);
- movdqa(ecx, xmm0);
- movdqa(xmm0, xmm4);
- movdqa(ecx + eax, xmm2);
- }
-}
-
-static void MC_put_xy_8_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
-{
- const uint8_t* edx = ref;
- uint8_t* ecx = dest;
- int eax = stride;
- int esi = height;
- int edi = eax + eax;
- __m128i xmm7, xmm0, xmm2, xmm1, xmm3, xmm4, xmm5;
- movdqa(xmm7, const_1_16_bytes);
- movlpd(xmm0, edx);
- movlpd(xmm1, edx + 1);
- for (; esi; edx += edi, ecx += edi, esi -= 2) {
- movlpd(xmm2, edx + eax);
- movlpd(xmm3, edx + eax + 1);
- movlpd(xmm4, edx + edi);
- movlpd(xmm5, edx + edi + 1);
- pavgb(xmm0, xmm1);
- pavgb(xmm2, xmm3);
- movdqa(xmm1, xmm5);
- pavgb(xmm5, xmm4);
- psubusb(xmm2, xmm7);
- pavgb(xmm0, xmm2);
- pavgb(xmm2, xmm5);
- movlpd(ecx, xmm0);
- movdqa(xmm0, xmm4);
- movlpd(ecx + eax, xmm2);
- }
-}
-
-static void MC_avg_o_16_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
-{
- const uint8_t* edx = ref;
- uint8_t* ecx = dest;
- int esi = height;
- int eax = stride;
- int edi = eax + eax;
- int ebx = edi + eax;
-
- for (; esi; edx += edi * 2, ecx += edi * 2, esi -= 4) {
- __m128i xmm0, xmm1, xmm2, xmm3;
- movdqu(xmm0, edx);
- movdqu(xmm1, edx + eax);
- movdqu(xmm2, edx + edi);
- movdqu(xmm3, edx + ebx);
- pavgb(xmm0, ecx);
- pavgb(xmm1, ecx + eax);
- pavgb(xmm2, ecx + edi);
- pavgb(xmm3, ecx + ebx);
- movdqa(ecx, xmm0);
- movdqa(ecx + eax, xmm1);
- movdqa(ecx + edi, xmm2);
- movdqa(ecx + ebx, xmm3);
- }
-}
-
-static void MC_avg_o_8_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
-{
- const uint8_t* edx = ref;
- uint8_t* ecx = dest;
- int esi = height;
- int eax = stride;
- int edi = eax + eax;
- int ebx = edi + eax;
-
- __m128i xmm0, xmm1, xmm2, xmm3;
- for (; esi; edx += edi * 2, ecx += edi * 2, esi -= 4) {
- movlpd(xmm0, edx);
- movhpd(xmm0, edx + eax);
- movlpd(xmm2, edx + edi);
- movhpd(xmm2, edx + ebx);
- movlpd(xmm1, ecx);
- movhpd(xmm1, ecx + eax);
- movlpd(xmm3, ecx + edi);
- movhpd(xmm3, ecx + ebx);
- pavgb(xmm0, xmm1);
- pavgb(xmm2, xmm3);
- movlpd(ecx, xmm0);
- movhpd(ecx + eax, xmm0);
- movlpd(ecx + edi, xmm2);
- movhpd(ecx + ebx, xmm2);
- }
-}
-
-static void MC_avg_x_16_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
-{
- const uint8_t* edx = ref;
- uint8_t* ecx = dest;
- int esi = height;
- int eax = stride;
- int edi = eax + eax;
- int ebx = edi + eax;
-
- __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7;
- for (; esi; edx += edi * 2, ecx += edi * 2, esi -= 4) {
- movdqu(xmm0, edx);
- movdqu(xmm1, edx + 1);
- movdqu(xmm2, edx + eax);
- movdqu(xmm3, edx + eax + 1);
- movdqu(xmm4, edx + edi);
- movdqu(xmm5, edx + edi + 1);
- movdqu(xmm6, edx + ebx);
- movdqu(xmm7, edx + ebx + 1);
- pavgb(xmm0, xmm1);
- pavgb(xmm2, xmm3);
- pavgb(xmm4, xmm5);
- pavgb(xmm6, xmm7);
- pavgb(xmm0, ecx);
- pavgb(xmm2, ecx + eax);
- pavgb(xmm4, ecx + edi);
- pavgb(xmm6, ecx + ebx);
- movdqa(ecx, xmm0);
- movdqa(ecx + eax, xmm2);
- movdqa(ecx + edi, xmm4);
- movdqa(ecx + ebx, xmm6);
- }
-}
-
-static void MC_avg_x_8_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
-{
- const uint8_t* edx = ref;
- uint8_t* ecx = dest;
- int esi = height;
- int eax = stride;
- int edi = eax + eax;
- int ebx = edi + eax;
-
- __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5;
- for (; esi; edx += edi * 2, ecx += edi * 2, esi -= 4) {
- movlpd(xmm0, edx);
- movlpd(xmm1, edx + 1);
- movhpd(xmm0, edx + eax);
- movhpd(xmm1, edx + eax + 1);
- movlpd(xmm2, edx + edi);
- movlpd(xmm3, edx + edi + 1);
- movhpd(xmm2, edx + ebx);
- movhpd(xmm3, edx + ebx + 1);
- movlpd(xmm4, ecx);
- movhpd(xmm4, ecx + eax);
- movlpd(xmm5, ecx + edi);
- movhpd(xmm5, ecx + ebx);
- pavgb(xmm0, xmm1);
- pavgb(xmm2, xmm3);
- pavgb(xmm0, xmm4);
- pavgb(xmm2, xmm5);
- movlpd(ecx, xmm0);
- movhpd(ecx + eax, xmm0);
- movlpd(ecx + edi, xmm2);
- movhpd(ecx + ebx, xmm2);
- }
-}
-
-static void MC_avg_y_16_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
-{
- const uint8_t* edx = ref;
- uint8_t* ecx = dest;
- int esi = height;
- int eax = stride;
- int edi = eax + eax;
- int ebx = edi + eax;
- __m128i xmm0, xmm1, xmm2, xmm3, xmm4;
-
- movdqu(xmm0, edx);
- for (; esi; edx += edi * 2, ecx += edi * 2, esi -= 4) {
- movdqu(xmm1, edx + eax);
- movdqu(xmm2, edx + edi);
- movdqu(xmm3, edx + ebx);
- movdqu(xmm4, edx + edi * 2);
- pavgb(xmm0, xmm1);
- pavgb(xmm1, xmm2);
- pavgb(xmm2, xmm3);
- pavgb(xmm3, xmm4);
- pavgb(xmm0, ecx);
- pavgb(xmm1, ecx + eax);
- pavgb(xmm2, ecx + edi);
- pavgb(xmm3, ecx + ebx);
- movdqa(ecx, xmm0);
- movdqa(ecx + eax, xmm1);
- movdqa(ecx + edi, xmm2);
- movdqa(ecx + ebx, xmm3);
- movdqa(xmm0, xmm4);
- }
-}
-
-static void MC_avg_y_8_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
-{
- const uint8_t* edx = ref;
- uint8_t* ecx = dest;
- int esi = height;
- int eax = stride;
- int edi = eax + eax;
- int ebx = edi + eax;
- __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5;
- movhpd(xmm0, edx);
- movlpd(xmm0, edx + eax);
- for (; esi; edx += edi * 2, ecx += edi * 2, esi -= 4) {
- movlhps(xmm1, xmm0);
- movlpd(xmm1, edx + edi);
- movlhps(xmm2, xmm1);
- movlpd(xmm2, edx + ebx);
- movlhps(xmm3, xmm2);
- movlpd(xmm3, edx + edi * 2);
- movhpd(xmm4, ecx);
- movlpd(xmm4, ecx + eax);
- movhpd(xmm5, ecx + edi);
- movlpd(xmm5, ecx + ebx);
- pavgb(xmm0, xmm1);
- pavgb(xmm2, xmm3);
- pavgb(xmm0, xmm4);
- pavgb(xmm2, xmm5);
- movhpd(ecx, xmm0);
- movlpd(ecx + eax, xmm0);
- movhpd(ecx + edi, xmm2);
- movlpd(ecx + ebx, xmm2);
- movdqa(xmm0, xmm3);
- }
-}
-
-static void MC_avg_xy_16_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
-{
- const uint8_t* edx = ref;
- uint8_t* ecx = dest;
- int esi = height;
- int eax = stride;
- int edi = eax + eax;
- __m128i xmm7, xmm0, xmm1, xmm2, xmm3, xmm4, xmm5;
- movdqa(xmm7, const_1_16_bytes);
- movdqu(xmm0, edx);
- movdqu(xmm1, edx + 1);
- for (; esi; edx += edi, ecx += edi, esi -= 2) {
- movdqu(xmm2, edx + eax);
- movdqu(xmm3, edx + eax + 1);
- movdqu(xmm4, edx + edi);
- movdqu(xmm5, edx + edi + 1);
- pavgb(xmm0, xmm1);
- pavgb(xmm2, xmm3);
- movdqa(xmm1, xmm5);
- pavgb(xmm5, xmm4);
- psubusb(xmm2, xmm7);
- pavgb(xmm0, xmm2);
- pavgb(xmm2, xmm5);
- pavgb(xmm0, ecx);
- pavgb(xmm2, ecx + eax);
- movdqa(ecx, xmm0);
- movdqa(xmm0, xmm4);
- movdqa(ecx + eax, xmm2);
- }
-}
-
-static void MC_avg_xy_8_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
-{
- const uint8_t* edx = ref;
- uint8_t* ecx = dest;
- int esi = height;
- int eax = stride;
- int edi = eax + eax;
- __m128i xmm7, xmm0, xmm2, xmm1, xmm3, xmm4;
- movdqa(xmm7, const_1_16_bytes);
- movhpd(xmm0, edx);
- movlpd(xmm0, edx + eax);
- movhpd(xmm2, edx + 1);
- movlpd(xmm2, edx + eax + 1);
- for (; esi; edx += edi, ecx += edi, esi -= 2) {
-
- movhpd(xmm1, edx + eax);
- movlpd(xmm1, edx + edi);
- movhpd(xmm3, edx + eax + 1);
- movlpd(xmm3, edx + edi + 1);
- pavgb(xmm0, xmm1);
- pavgb(xmm2, xmm3);
- psubusb(xmm0, xmm7);
- pavgb(xmm0, xmm2);
- movhpd(xmm4, ecx);
- movlpd(xmm4, ecx + eax);
- pavgb(xmm0, xmm4);
- movhpd(ecx, xmm0);
- movlpd(ecx + eax, xmm0);
- movdqa(xmm0, xmm1);
- movdqa(xmm2, xmm3);
- }
-}
-
-mpeg2_mc_t mpeg2_mc_sse2 = {
- {
- MC_put_o_16_sse2, MC_put_x_16_sse2, MC_put_y_16_sse2, MC_put_xy_16_sse2,
- MC_put_o_8_sse2, MC_put_x_8_sse2, MC_put_y_8_sse2, MC_put_xy_8_sse2
- },
- {
- MC_avg_o_16_sse2, MC_avg_x_16_sse2, MC_avg_y_16_sse2, MC_avg_xy_16_sse2,
- MC_avg_o_8_sse2, MC_avg_x_8_sse2, MC_avg_y_8_sse2, MC_avg_xy_8_sse2
- }
-};
diff --git a/src/filters/transform/Mpeg2DecFilter/motion_comp_mmx.obj b/src/filters/transform/Mpeg2DecFilter/motion_comp_mmx.obj
deleted file mode 100644
index 6be317582..000000000
--- a/src/filters/transform/Mpeg2DecFilter/motion_comp_mmx.obj
+++ /dev/null
Binary files differ
diff --git a/src/filters/transform/Mpeg2DecFilter/resource.h b/src/filters/transform/Mpeg2DecFilter/resource.h
deleted file mode 100644
index 21a1b6a08..000000000
--- a/src/filters/transform/Mpeg2DecFilter/resource.h
+++ /dev/null
@@ -1,27 +0,0 @@
-//{{NO_DEPENDENCIES}}
-// Microsoft Visual C++ generated include file.
-// Used by Mpeg2DecFilter.rc
-//
-#define IDS_FILTER_SETTINGS_CAPTION 7000
-#define IDS_MPEG2_ENABLE_PLANAR 7500
-#define IDS_MPEG2_INTERLACE_FLAG 7501
-#define IDS_MPEG2_FORCED_SUBS 7502
-#define IDS_MPEG2_DEINTERLACING 7503
-#define IDS_MPEG2_BRIGHTNESS 7504
-#define IDS_MPEG2_RESET 7505
-#define IDS_MPEG2_NOTE1 7506
-#define IDS_MPEG2_CONTRAST 7507
-#define IDS_MPEG2_HUE 7508
-#define IDS_MPEG2_SATURATION 7509
-#define IDS_MPEG2_READ_AR 7511
-
-// Next default values for new objects
-//
-#ifdef APSTUDIO_INVOKED
-#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 102
-#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1001
-#define _APS_NEXT_SYMED_VALUE 101
-#endif
-#endif
diff --git a/src/filters/transform/Mpeg2DecFilter/stdafx.cpp b/src/filters/transform/Mpeg2DecFilter/stdafx.cpp
deleted file mode 100644
index 784f2cebc..000000000
--- a/src/filters/transform/Mpeg2DecFilter/stdafx.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * (C) 2003-2006 Gabest
- * (C) 2006-2012 see Authors.txt
- *
- * This file is part of MPC-HC.
- *
- * MPC-HC 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 3 of the License, or
- * (at your option) any later version.
- *
- * MPC-HC 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 this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "stdafx.h"
diff --git a/src/filters/transform/Mpeg2DecFilter/stdafx.h b/src/filters/transform/Mpeg2DecFilter/stdafx.h
deleted file mode 100644
index 5b6b09e05..000000000
--- a/src/filters/transform/Mpeg2DecFilter/stdafx.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * (C) 2003-2006 Gabest
- * (C) 2006-2012 see Authors.txt
- *
- * This file is part of MPC-HC.
- *
- * MPC-HC 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 3 of the License, or
- * (at your option) any later version.
- *
- * MPC-HC 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 this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#pragma once
-
-#include "../../../DSUtil/SharedInclude.h"
-#include "../../../../include/stdafx_common.h"
-#include "../../../../include/stdafx_common_afx.h"
-#include "../../../../include/stdafx_common_dshow.h"