diff options
author | XhmikosR <xhmikosr@users.sourceforge.net> | 2011-12-03 19:03:20 +0400 |
---|---|---|
committer | XhmikosR <xhmikosr@users.sourceforge.net> | 2011-12-03 19:03:20 +0400 |
commit | e7183fa2f8f6c6f489f029c7d8105a976306f44b (patch) | |
tree | bfe1dac3b4307a6b61544148bbe7456355925c53 /src | |
parent | a57b95993949656236b352ebd66db1ecf2eaf7d5 (diff) |
update VirtualDub to v1.10.1-test16
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@3877 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src')
28 files changed, 469 insertions, 195 deletions
diff --git a/src/thirdparty/VirtualDub/Kasumi/h/stdafx.h b/src/thirdparty/VirtualDub/Kasumi/h/stdafx.h index 91412a2ea..0ba6b7915 100644 --- a/src/thirdparty/VirtualDub/Kasumi/h/stdafx.h +++ b/src/thirdparty/VirtualDub/Kasumi/h/stdafx.h @@ -17,6 +17,6 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <vd2/system/vdtypes.h>
-#include <vd2/system/math.h>
+#include <vd2/system/math.h> // MPC-HC patch
#include <vd2/Kasumi/pixmap.h>
-#include <uberblit.h>
+#include <uberblit.h>
\ No newline at end of file diff --git a/src/thirdparty/VirtualDub/Kasumi/source/pixmaputils.cpp b/src/thirdparty/VirtualDub/Kasumi/source/pixmaputils.cpp index d43335a1b..185b39c8d 100644 --- a/src/thirdparty/VirtualDub/Kasumi/source/pixmaputils.cpp +++ b/src/thirdparty/VirtualDub/Kasumi/source/pixmaputils.cpp @@ -17,6 +17,7 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <stdafx.h>
+#include <vd2/system/error.h>
#include <vd2/system/vdtypes.h>
#include <vd2/Kasumi/pixmaputils.h>
#include <vd2/system/memory.h>
@@ -414,17 +415,25 @@ void VDPixmapBuffer::init(sint32 width, sint32 height, int f) { sint32 subh = -(-height >> srcinfo.auxhbits);
ptrdiff_t mainpitch = (srcinfo.qsize * qw + 15) & ~15;
ptrdiff_t subpitch = (srcinfo.auxsize * subw + 15) & ~15;
- size_t mainsize = mainpitch * qh;
- size_t subsize = subpitch * subh;
- size_t totalsize = mainsize + subsize*srcinfo.auxbufs + 4 * srcinfo.palsize;
+ uint64 mainsize = (uint64)mainpitch * qh;
+ uint64 subsize = (uint64)subpitch * subh;
+ uint64 totalsize64 = mainsize + subsize*srcinfo.auxbufs + 4 * srcinfo.palsize;
#ifdef _DEBUG
- totalsize += 28;
+ totalsize64 += 28;
#endif
+ // reject huge allocations
+ if (totalsize64 > (size_t)-1 - 4096)
+ throw MyMemoryError();
+
+ size_t totalsize = (uint32)totalsize64;
+
if (mLinearSize != totalsize) {
clear();
- mpBuffer = new char[totalsize + 15];
+ mpBuffer = new_nothrow char[totalsize + 15];
+ if (!mpBuffer)
+ throw MyMemoryError(totalsize + 15);
mLinearSize = totalsize;
}
@@ -474,54 +483,63 @@ void VDPixmapBuffer::init(sint32 width, sint32 height, int f) { #endif
}
-void VDPixmapBuffer::init(const VDPixmapLayout& layout) {
+void VDPixmapBuffer::init(const VDPixmapLayout& layout, uint32 additionalPadding) {
const VDPixmapFormatInfo& srcinfo = VDPixmapGetInfo(layout.format);
sint32 qw = (layout.w + srcinfo.qw - 1) / srcinfo.qw;
sint32 qh = -(-layout.h >> srcinfo.qhbits);
sint32 subw = -(-layout.w >> srcinfo.auxwbits);
sint32 subh = -(-layout.h >> srcinfo.auxhbits);
- ptrdiff_t mino=0, maxo=0;
+ sint64 mino=0, maxo=0;
if (layout.pitch < 0) {
- mino = std::min<ptrdiff_t>(mino, layout.data + layout.pitch * (qh-1));
- maxo = std::max<ptrdiff_t>(maxo, layout.data - layout.pitch);
+ mino = std::min<sint64>(mino, layout.data + (sint64)layout.pitch * (qh-1));
+ maxo = std::max<sint64>(maxo, layout.data - (sint64)layout.pitch);
} else {
- mino = std::min<ptrdiff_t>(mino, layout.data);
- maxo = std::max<ptrdiff_t>(maxo, layout.data + layout.pitch*qh);
+ mino = std::min<sint64>(mino, layout.data);
+ maxo = std::max<sint64>(maxo, layout.data + (sint64)layout.pitch*qh);
}
if (srcinfo.auxbufs >= 1) {
if (layout.pitch2 < 0) {
- mino = std::min<ptrdiff_t>(mino, layout.data2 + layout.pitch2 * (subh-1));
- maxo = std::max<ptrdiff_t>(maxo, layout.data2 - layout.pitch2);
+ mino = std::min<sint64>(mino, layout.data2 + (sint64)layout.pitch2 * (subh-1));
+ maxo = std::max<sint64>(maxo, layout.data2 - (sint64)layout.pitch2);
} else {
- mino = std::min<ptrdiff_t>(mino, layout.data2);
- maxo = std::max<ptrdiff_t>(maxo, layout.data2 + layout.pitch2*subh);
+ mino = std::min<sint64>(mino, layout.data2);
+ maxo = std::max<sint64>(maxo, layout.data2 + (sint64)layout.pitch2*subh);
}
if (srcinfo.auxbufs >= 2) {
if (layout.pitch3 < 0) {
- mino = std::min<ptrdiff_t>(mino, layout.data3 + layout.pitch3 * (subh-1));
- maxo = std::max<ptrdiff_t>(maxo, layout.data3 - layout.pitch3);
+ mino = std::min<sint64>(mino, layout.data3 + (sint64)layout.pitch3 * (subh-1));
+ maxo = std::max<sint64>(maxo, layout.data3 - (sint64)layout.pitch3);
} else {
- mino = std::min<ptrdiff_t>(mino, layout.data3);
- maxo = std::max<ptrdiff_t>(maxo, layout.data3 + layout.pitch3*subh);
+ mino = std::min<sint64>(mino, layout.data3);
+ maxo = std::max<sint64>(maxo, layout.data3 + (sint64)layout.pitch3*subh);
}
}
}
- ptrdiff_t linsize = ((maxo - mino + 3) & ~(uintptr)3);
+ sint64 linsize64 = ((maxo - mino + 3) & ~(uint64)3);
- ptrdiff_t totalsize = linsize + 4*srcinfo.palsize;
+ sint64 totalsize64 = linsize64 + 4*srcinfo.palsize + additionalPadding;
#ifdef _DEBUG
- totalsize += 28;
+ totalsize64 += 28;
#endif
+ // reject huge allocations
+ if (totalsize64 > (size_t)-1 - 4096)
+ throw MyMemoryError();
+
+ size_t totalsize = (uint32)totalsize64;
+ ptrdiff_t linsize = (uint32)linsize64;
+
if (mLinearSize != totalsize) {
clear();
- mpBuffer = new char[totalsize + 15];
+ mpBuffer = new_nothrow char[totalsize + 15];
+ if (!mpBuffer)
+ throw MyMemoryError(totalsize + 15);
mLinearSize = totalsize;
}
diff --git a/src/thirdparty/VirtualDub/Kasumi/source/resample_stages_x64.cpp b/src/thirdparty/VirtualDub/Kasumi/source/resample_stages_x64.cpp index 5d2cd6fa3..50e623ef0 100644 --- a/src/thirdparty/VirtualDub/Kasumi/source/resample_stages_x64.cpp +++ b/src/thirdparty/VirtualDub/Kasumi/source/resample_stages_x64.cpp @@ -1,4 +1,4 @@ -#include <stdafx.h>
+#include <stdafx.h> // MPC-HC patch
#include "resample_stages_x64.h"
extern "C" long vdasm_resize_table_col_SSE2(uint32 *out, const uint32 *const*in_table, const int *filter, int filter_width, uint32 w);
diff --git a/src/thirdparty/VirtualDub/Kasumi/source/stdafx.cpp b/src/thirdparty/VirtualDub/Kasumi/source/stdafx.cpp index 8eed47b75..13d8f1350 100644 --- a/src/thirdparty/VirtualDub/Kasumi/source/stdafx.cpp +++ b/src/thirdparty/VirtualDub/Kasumi/source/stdafx.cpp @@ -16,4 +16,4 @@ // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#include "stdafx.h"
+#include "stdafx.h"
\ No newline at end of file diff --git a/src/thirdparty/VirtualDub/h/vd2/Kasumi/pixmaputils.h b/src/thirdparty/VirtualDub/h/vd2/Kasumi/pixmaputils.h index 0d9e50cfd..bf5fd6203 100644 --- a/src/thirdparty/VirtualDub/h/vd2/Kasumi/pixmaputils.h +++ b/src/thirdparty/VirtualDub/h/vd2/Kasumi/pixmaputils.h @@ -156,7 +156,7 @@ public: #endif
void init(sint32 w, sint32 h, int format);
- void init(const VDPixmapLayout&);
+ void init(const VDPixmapLayout&, uint32 additionalPadding = 0);
void assign(const VDPixmap& src);
diff --git a/src/thirdparty/VirtualDub/h/vd2/system/Error.h b/src/thirdparty/VirtualDub/h/vd2/system/Error.h index ca11527f9..519d7faf6 100644 --- a/src/thirdparty/VirtualDub/h/vd2/system/Error.h +++ b/src/thirdparty/VirtualDub/h/vd2/system/Error.h @@ -94,6 +94,7 @@ public: class MyMemoryError : public MyError {
public:
MyMemoryError();
+ MyMemoryError(size_t attemptedSize);
};
class MyWin32Error : public MyError {
diff --git a/src/thirdparty/VirtualDub/h/vd2/system/VDString.h b/src/thirdparty/VirtualDub/h/vd2/system/VDString.h index 7fd2a7a1a..ed96a3635 100644 --- a/src/thirdparty/VirtualDub/h/vd2/system/VDString.h +++ b/src/thirdparty/VirtualDub/h/vd2/system/VDString.h @@ -752,6 +752,10 @@ public: return l1 < l2 ? -1 : +1;
}
+ int comparei(const wchar_t *s) const {
+ return comparei(VDStringSpanW(s));
+ }
+
int comparei(const VDStringSpanW& s) const {
size_type l1 = (size_type)(mpEnd - mpBegin);
size_type l2 = (size_type)(s.mpEnd - s.mpBegin);
diff --git a/src/thirdparty/VirtualDub/h/vd2/system/bitmath.h b/src/thirdparty/VirtualDub/h/vd2/system/bitmath.h index ebc3fa23b..c6bd76078 100644 --- a/src/thirdparty/VirtualDub/h/vd2/system/bitmath.h +++ b/src/thirdparty/VirtualDub/h/vd2/system/bitmath.h @@ -61,8 +61,8 @@ inline float VDGetIntAsFloat(sint32 i) { ///////////////////////////////////////////////////////////////////////////////
-#ifdef VD_COMPILER_MSVC_VC8
- #include <intrin.h>
+#ifdef VD_COMPILER_MSVC_VC8_OR_LATER
+ #include <vd2/system/win32/intrin.h>
#pragma intrinsic(_BitScanForward)
#pragma intrinsic(_BitScanReverse)
diff --git a/src/thirdparty/VirtualDub/h/vd2/system/cpuaccel.h b/src/thirdparty/VirtualDub/h/vd2/system/cpuaccel.h index a15bc8be9..78f158ebf 100644 --- a/src/thirdparty/VirtualDub/h/vd2/system/cpuaccel.h +++ b/src/thirdparty/VirtualDub/h/vd2/system/cpuaccel.h @@ -37,6 +37,7 @@ #define CPUF_SUPPORTS_SSE3 (0x00000100L)
#define CPUF_SUPPORTS_SSSE3 (0x00000200L)
#define CPUF_SUPPORTS_SSE41 (0x00000400L)
+#define CPUF_SUPPORTS_AVX (0x00000800L)
#define CPUF_SUPPORTS_MASK (0x000007FFL)
long CPUCheckForExtensions();
diff --git a/src/thirdparty/VirtualDub/h/vd2/system/int128.h b/src/thirdparty/VirtualDub/h/vd2/system/int128.h index da86c4878..ebef416cc 100644 --- a/src/thirdparty/VirtualDub/h/vd2/system/int128.h +++ b/src/thirdparty/VirtualDub/h/vd2/system/int128.h @@ -93,6 +93,8 @@ public: q[1] = hi;
}
+ explicit inline vdint128(const vduint128& x);
+
sint64 getHi() const { return q[1]; }
uint64 getLo() const { return q[0]; }
@@ -239,6 +241,8 @@ public: q[1] = hi;
}
+ explicit inline vduint128(const vdint128& x);
+
uint64 getHi() const { return q[1]; }
uint64 getLo() const { return q[0]; }
@@ -346,6 +350,16 @@ public: #endif
};
+inline vdint128::vdint128(const vduint128& x) {
+ q[0] = x.q[0];
+ q[1] = x.q[1];
+}
+
+inline vduint128::vduint128(const vdint128& x) {
+ q[0] = x.q[0];
+ q[1] = x.q[1];
+}
+
#ifdef _M_AMD64
inline vduint128 VDUMul64x64To128(uint64 x, uint64 y) {
vduint128 result;
diff --git a/src/thirdparty/VirtualDub/h/vd2/system/linearalloc.h b/src/thirdparty/VirtualDub/h/vd2/system/linearalloc.h index 8d2570c8e..4fd847152 100644 --- a/src/thirdparty/VirtualDub/h/vd2/system/linearalloc.h +++ b/src/thirdparty/VirtualDub/h/vd2/system/linearalloc.h @@ -7,6 +7,8 @@ class VDLinearAllocator { public:
explicit VDLinearAllocator(uint32 blockSize = 4096);
~VDLinearAllocator();
+
+ void Clear();
void *Allocate(size_t bytes) {
void *p = mpAllocPtr;
diff --git a/src/thirdparty/VirtualDub/h/vd2/system/math.h b/src/thirdparty/VirtualDub/h/vd2/system/math.h index c395bcbc7..fbef306c6 100644 --- a/src/thirdparty/VirtualDub/h/vd2/system/math.h +++ b/src/thirdparty/VirtualDub/h/vd2/system/math.h @@ -47,6 +47,10 @@ namespace nsVDMath { // Integer clamping functions
//
#ifdef _M_IX86
+ inline uint32 VDClampToUint32(uint64 v) {
+ return v >= 0x100000000UL ? 0xFFFFFFFFUL : (uint32)v;
+ }
+
inline uint32 VDClampToUint32(sint64 v) {
union U {
__int64 v64;
@@ -58,6 +62,10 @@ namespace nsVDMath { return ((U *)&v)->v32.hi ? ~(((U *)&v)->v32.hi >> 31) : ((U *)&v)->v32.lo;
}
+
+ inline uint32 VDClampToUint32(sint32 v) {
+ return v < 0 ? 0 : (uint32)v;
+ }
#else
inline uint32 VDClampToUint32(sint64 v) {
uint32 r = (uint32)v;
diff --git a/src/thirdparty/VirtualDub/h/vd2/system/refcount.h b/src/thirdparty/VirtualDub/h/vd2/system/refcount.h index e2bd70f57..7f5a34a3f 100644 --- a/src/thirdparty/VirtualDub/h/vd2/system/refcount.h +++ b/src/thirdparty/VirtualDub/h/vd2/system/refcount.h @@ -308,4 +308,16 @@ inline vdsaferelease_t& operator,(vdsaferelease_t& x, T *& p) { return x;
}
+///////////////////////////////////////////////////////////////////////////
+
+template<class T>
+void VDReleaseObjects(const T& container) {
+ for(typename T::const_iterator it(container.begin()), itEnd(container.end());
+ it != itEnd;
+ ++it)
+ {
+ (*it)->Release();
+ }
+}
+
#endif
diff --git a/src/thirdparty/VirtualDub/h/vd2/system/vdstl_hashmap.h b/src/thirdparty/VirtualDub/h/vd2/system/vdstl_hashmap.h index 8715cbf34..14460d997 100644 --- a/src/thirdparty/VirtualDub/h/vd2/system/vdstl_hashmap.h +++ b/src/thirdparty/VirtualDub/h/vd2/system/vdstl_hashmap.h @@ -64,6 +64,9 @@ public: // iterator insert(iterator hint, const value_type& obj); // TODO
// const_iterator insert(const_iterator hint, const value_type& obj); // TODO
+ template<class U>
+ insert_return_type insert_as(const U& k); // extension
+
iterator erase(iterator position);
const_iterator erase(const_iterator position);
size_type erase(const key_type& k);
@@ -243,6 +246,40 @@ typename vdhashmap<K, V, Hash, Pred, A>::insert_return_type vdhashmap<K, V, Hash }
template<class K, class V, class Hash, class Pred, class A>
+template<class U>
+typename vdhashmap<K, V, Hash, Pred, A>::insert_return_type vdhashmap<K, V, Hash, Pred, A>::insert_as(const U& key) {
+ if (mElementCount >= mBucketCount)
+ rehash_to_size(mElementCount + 1);
+
+ size_type bucket = mHasher(key) % mBucketCount;
+
+ for(node_type *p = static_cast<node_type *>(mpBucketStart[bucket]); p; p = static_cast<node_type *>(p->mpHashNext)) {
+ if (mPred(p->mData.first, key))
+ return std::pair<iterator, bool>(iterator(p, &mpBucketStart[bucket], mpBucketEnd), false);
+ }
+
+ node_type *node = mAllocator.allocate(1);
+ try {
+ new(node) node_type(static_cast<node_type *>(mpBucketStart[bucket]));
+
+ try {
+ node->mData.first = key;
+ } catch(...) {
+ node->~node_type();
+ }
+
+ } catch(...) {
+ mAllocator.deallocate(node, 1);
+ throw;
+ }
+
+ mpBucketStart[bucket] = node;
+ ++mElementCount;
+
+ return std::pair<iterator, bool>(iterator(node, &mpBucketStart[bucket], mpBucketEnd), true);
+}
+
+template<class K, class V, class Hash, class Pred, class A>
typename vdhashmap<K, V, Hash, Pred, A>::iterator vdhashmap<K, V, Hash, Pred, A>::erase(iterator position) {
size_type bucket = mHasher(position->first) % mBucketCount;
vdhashtable_base_node *prev = NULL;
diff --git a/src/thirdparty/VirtualDub/h/vd2/system/vdstl_hashtable.h b/src/thirdparty/VirtualDub/h/vd2/system/vdstl_hashtable.h index 83b365bd8..824e14981 100644 --- a/src/thirdparty/VirtualDub/h/vd2/system/vdstl_hashtable.h +++ b/src/thirdparty/VirtualDub/h/vd2/system/vdstl_hashtable.h @@ -71,6 +71,10 @@ struct vdhashtable_node : public vdhashtable_base_node { T mData;
vdhashtable_node() {}
+ vdhashtable_node(vdhashtable_node<T> *next) : mData() {
+ mpHashNext = next;
+ }
+
vdhashtable_node(vdhashtable_node<T> *next, const T& val) : mData(val) {
mpHashNext = next;
}
diff --git a/src/thirdparty/VirtualDub/h/vd2/system/vdtypes.h b/src/thirdparty/VirtualDub/h/vd2/system/vdtypes.h index b38e1461d..11487457c 100644 --- a/src/thirdparty/VirtualDub/h/vd2/system/vdtypes.h +++ b/src/thirdparty/VirtualDub/h/vd2/system/vdtypes.h @@ -53,6 +53,7 @@ #if _MSC_VER >= 1400
#define VD_COMPILER_MSVC_VC8 1
+ #define VD_COMPILER_MSVC_VC8_OR_LATER 1
#if _MSC_FULL_VER == 140040310
#define VD_COMPILER_MSVC_VC8_PSDK 1
diff --git a/src/thirdparty/VirtualDub/h/vd2/system/win32/intrin.h b/src/thirdparty/VirtualDub/h/vd2/system/win32/intrin.h new file mode 100644 index 000000000..91a78db89 --- /dev/null +++ b/src/thirdparty/VirtualDub/h/vd2/system/win32/intrin.h @@ -0,0 +1,52 @@ +// VirtualDub - Video processing and capture application
+// System library component
+// Copyright (C) 1998-2011 Avery Lee, All Rights Reserved.
+//
+// Beginning with 1.6.0, the VirtualDub system library is licensed
+// differently than the remainder of VirtualDub. This particular file is
+// thus licensed as follows (the "zlib" license):
+//
+// This software is provided 'as-is', without any express or implied
+// warranty. In no event will the authors be held liable for any
+// damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it
+// freely, subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented; you must
+// not claim that you wrote the original software. If you use this
+// software in a product, an acknowledgment in the product
+// documentation would be appreciated but is not required.
+// 2. Altered source versions must be plainly marked as such, and must
+// not be misrepresented as being the original software.
+// 3. This notice may not be removed or altered from any source
+// distribution.
+
+#ifndef f_VD2_SYSTEM_WIN32_INTRIN_H
+#define f_VD2_SYSTEM_WIN32_INTRIN_H
+
+#pragma once
+
+// The Windows SDK conflicts with the VS2005 declaration of a couple
+// of intrinsics starting with the Vista SDK. The conflict is between
+// intrin.h and winnt.h. To work around this, we wrap intrin.h and
+// rename its declaration.
+#pragma push_macro("_interlockedbittestandset")
+#pragma push_macro("_interlockedbittestandreset")
+#pragma push_macro("_interlockedbittestandset64")
+#pragma push_macro("_interlockedbittestandreset64")
+
+#define _interlockedbittestandset _interlockedbittestandset_vc
+#define _interlockedbittestandreset _interlockedbittestandreset_vc
+#define _interlockedbittestandset64 _interlockedbittestandset64_vc
+#define _interlockedbittestandreset64 _interlockedbittestandreset64_vc
+
+#include <intrin.h>
+
+#pragma pop_macro("_interlockedbittestandreset64")
+#pragma pop_macro("_interlockedbittestandset64")
+#pragma pop_macro("_interlockedbittestandreset")
+#pragma pop_macro("_interlockedbittestandset")
+
+#endif
diff --git a/src/thirdparty/VirtualDub/h/vd2/system/zip.h b/src/thirdparty/VirtualDub/h/vd2/system/zip.h index 06b864ccf..1c0e696f5 100644 --- a/src/thirdparty/VirtualDub/h/vd2/system/zip.h +++ b/src/thirdparty/VirtualDub/h/vd2/system/zip.h @@ -217,4 +217,18 @@ protected: IVDRandomAccessStream *mpStream;
};
+class VDGUnzipStream : public VDZipStream {
+public:
+ VDGUnzipStream();
+ VDGUnzipStream(IVDStream *pSrc, uint64 limit);
+ ~VDGUnzipStream();
+
+ void Init(IVDStream *pSrc, uint64 limit);
+
+ const char *GetFilename() const { return mFilename.c_str(); }
+
+protected:
+ VDStringA mFilename;
+};
+
#endif
diff --git a/src/thirdparty/VirtualDub/system/h/stdafx.h b/src/thirdparty/VirtualDub/system/h/stdafx.h index 26c63eaf8..2fbf125e2 100644 --- a/src/thirdparty/VirtualDub/system/h/stdafx.h +++ b/src/thirdparty/VirtualDub/system/h/stdafx.h @@ -1,11 +1,22 @@ +/* MPC-HC comment out
+// Detect the Windows SDK in use and select Windows 2000 baseline
+// if the Vista SDK, else Windows 98 baseline.
+#include <ntverp.h>
+#if VER_PRODUCTBUILD > 6000
+#define _WIN32_WINNT 0x0500
+#else
+#define _WIN32_WINNT 0x0410
+#endif
+*/
+
#include <vd2/system/vdtypes.h>
#include <vd2/system/atomic.h>
#include <vd2/system/thread.h>
#include <vd2/system/error.h>
-#include <vd2/system/filesys.h>
+#include <vd2/system/filesys.h> // MPC-HC patch
#include <windows.h>
#include <process.h>
-#include <intrin.h>
+#include <vd2/system/win32/intrin.h>
#include <string.h>
#include <stdarg.h>
#include <math.h>
diff --git a/src/thirdparty/VirtualDub/system/linearalloc.cpp b/src/thirdparty/VirtualDub/system/linearalloc.cpp index c6b8dabc2..4eb9bb772 100644 --- a/src/thirdparty/VirtualDub/system/linearalloc.cpp +++ b/src/thirdparty/VirtualDub/system/linearalloc.cpp @@ -11,6 +11,10 @@ VDLinearAllocator::VDLinearAllocator(uint32 blockSize) }
VDLinearAllocator::~VDLinearAllocator() {
+ Clear();
+}
+
+void VDLinearAllocator::Clear() {
Block *p = mpBlocks;
while(p) {
@@ -20,6 +24,8 @@ VDLinearAllocator::~VDLinearAllocator() { p = next;
}
+
+ mpBlocks = NULL;
}
void *VDLinearAllocator::AllocateSlow(size_t bytes) {
@@ -31,18 +37,21 @@ void *VDLinearAllocator::AllocateSlow(size_t bytes) { if (!block)
throw MyMemoryError();
- p = block + 1;
+ mAllocLeft = 0;
} else {
block = (Block *)malloc(sizeof(Block) + mBlockSize);
+
if (!block)
throw MyMemoryError();
- p = block + 1;
- mpAllocPtr = (char *)p + bytes;
mAllocLeft = mBlockSize - bytes;
+
}
+ p = block + 1;
+ mpAllocPtr = (char *)p + bytes;
+
block->mpNext = mpBlocks;
mpBlocks = block;
diff --git a/src/thirdparty/VirtualDub/system/source/Error.cpp b/src/thirdparty/VirtualDub/system/source/Error.cpp index c8e9848ef..dce1af287 100644 --- a/src/thirdparty/VirtualDub/system/source/Error.cpp +++ b/src/thirdparty/VirtualDub/system/source/Error.cpp @@ -231,6 +231,10 @@ MyMemoryError::MyMemoryError() { setf("Out of memory");
}
+MyMemoryError::MyMemoryError(size_t requestedSize) {
+ setf("Out of memory (unable to allocate %llu bytes)", (unsigned long long)requestedSize);
+}
+
MyWin32Error::MyWin32Error(const char *format, uint32 err, ...)
: mWin32Error(err)
{
diff --git a/src/thirdparty/VirtualDub/system/source/a64_cpuaccel.asm b/src/thirdparty/VirtualDub/system/source/a64_cpuaccel.asm new file mode 100644 index 000000000..278754c4e --- /dev/null +++ b/src/thirdparty/VirtualDub/system/source/a64_cpuaccel.asm @@ -0,0 +1,42 @@ +; VirtualDub - Video processing and capture application
+; System library component
+; Copyright (C) 1998-2006 Avery Lee, All Rights Reserved.
+;
+; Beginning with 1.6.0, the VirtualDub system library is licensed
+; differently than the remainder of VirtualDub. This particular file is
+; thus licensed as follows (the "zlib" license):
+;
+; This software is provided 'as-is', without any express or implied
+; warranty. In no event will the authors be held liable for any
+; damages arising from the use of this software.
+;
+; Permission is granted to anyone to use this software for any purpose,
+; including commercial applications, and to alter it and redistribute it
+; freely, subject to the following restrictions:
+;
+; 1. The origin of this software must not be misrepresented; you must
+; not claim that you wrote the original software. If you use this
+; software in a product, an acknowledgment in the product
+; documentation would be appreciated but is not required.
+; 2. Altered source versions must be plainly marked as such, and must
+; not be misrepresented as being the original software.
+; 3. This notice may not be removed or altered from any source
+; distribution.
+
+ segment .text
+
+;--------------------------------------------------------------------------
+ global VDIsAVXSupportedByOS
+VDIsAVXSupportedByOS:
+ xor ecx, ecx
+ xgetbv
+ and al, 6
+ cmp al, 6
+ jnz .notsupported
+ mov eax, 1
+ ret
+.notsupported:
+ xor eax, eax
+ ret
+
+ end
diff --git a/src/thirdparty/VirtualDub/system/source/cpuaccel.cpp b/src/thirdparty/VirtualDub/system/source/cpuaccel.cpp index a3cb1cf3b..12329cbf0 100644 --- a/src/thirdparty/VirtualDub/system/source/cpuaccel.cpp +++ b/src/thirdparty/VirtualDub/system/source/cpuaccel.cpp @@ -36,188 +36,123 @@ extern "C" { bool FPU_enabled, MMX_enabled, SSE_enabled, ISSE_enabled, SSE2_enabled;
};
+namespace {
+#ifdef _M_IX86
+ bool VDIsAVXSupportedByOS() {
+ uint32 xfeature_enabled_mask;
-#ifdef _M_AMD64
-
- long CPUCheckForExtensions() {
- long flags = CPUF_SUPPORTS_FPU;
+ __asm {
+ xor ecx, ecx
+ __emit 0x0f ;xgetbv
+ __emit 0x01
+ __emit 0xd0
+ mov dword ptr xfeature_enabled_mask, eax
+ }
- // This code used to use IsProcessorFeaturePresent(), but this function is somewhat
- // suboptimal in Win64 -- for one thing, it doesn't return true for MMX, at least
- // on Vista 64.
+ return (xfeature_enabled_mask & 0x06) == 0x06;
+ }
- // check for SSE3, SSSE3, SSE4.1
- int cpuInfo[4];
- __cpuid(cpuInfo, 1);
+ bool IsSSESupported() {
- if (cpuInfo[3] & (1 << 23))
- flags |= CPUF_SUPPORTS_MMX;
+ return true;
+ }
+#else
+ extern "C" bool VDIsAVXSupportedByOS();
- if (cpuInfo[3] & (1 << 25))
- flags |= CPUF_SUPPORTS_SSE | CPUF_SUPPORTS_INTEGER_SSE;
+ bool IsSSESupported() {
+ return true;
+ }
+#endif
+}
- if (cpuInfo[3] & (1 << 26))
- flags |= CPUF_SUPPORTS_SSE2;
+// This code used to use IsProcessorFeaturePresent(), but this function is somewhat
+// suboptimal in Win64 -- for one thing, it doesn't return true for MMX, at least
+// on Vista 64.
+long CPUCheckForExtensions() {
+ // check for CPUID (x86 only)
+#ifdef _M_IX86
+ uint32 id;
+ __asm {
+ pushfd
+ or dword ptr [esp], 00200000h ;set the ID bit
+ popfd
+ pushfd ;flags -> EAX
+ pop dword ptr id
+ }
- if (cpuInfo[2] & 0x00000001)
- flags |= CPUF_SUPPORTS_SSE3;
+ if (!(id & 0x00200000)) {
+ // if we don't have CPUID, we probably won't want to try FPU optimizations
+ // (80486).
+ return 0;
+ }
+#endif
- if (cpuInfo[2] & 0x00000200)
- flags |= CPUF_SUPPORTS_SSSE3;
+ // check for features register
+ long flags = CPUF_SUPPORTS_FPU | CPUF_SUPPORTS_CPUID;
- if (cpuInfo[2] & 0x00080000)
- flags |= CPUF_SUPPORTS_SSE41;
+ int cpuInfo[4];
+ __cpuid(cpuInfo, 0);
+ if (cpuInfo[0] == 0)
+ return flags;
- // check for 3DNow!, 3DNow! extensions
- __cpuid(cpuInfo, 0x80000000);
- if (cpuInfo[0] >= 0x80000001) {
- __cpuid(cpuInfo, 0x80000001);
+ __cpuid(cpuInfo, 1);
- if (cpuInfo[3] & (1 << 31))
- flags |= CPUF_SUPPORTS_3DNOW;
+ if (cpuInfo[3] & (1 << 23))
+ flags |= CPUF_SUPPORTS_MMX;
- if (cpuInfo[3] & (1 << 30))
- flags |= CPUF_SUPPORTS_3DNOW_EXT;
+ if (cpuInfo[3] & (1 << 25)) {
+ // Check if SSE is actually supported.
+ bool sseSupported = true;
- if (cpuInfo[3] & (1 << 22))
- flags |= CPUF_SUPPORTS_INTEGER_SSE;
+#ifdef _M_IX86
+ __try {
+ __asm andps xmm0,xmm0
+ } __except(EXCEPTION_EXECUTE_HANDLER) {
+ if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
+ sseSupported = false;
}
+#endif
+
+ if (sseSupported) {
+ flags |= CPUF_SUPPORTS_SSE | CPUF_SUPPORTS_INTEGER_SSE;
- return flags;
- }
+ if (cpuInfo[3] & (1 << 26))
+ flags |= CPUF_SUPPORTS_SSE2;
-#else
+ if (cpuInfo[2] & 0x00000001)
+ flags |= CPUF_SUPPORTS_SSE3;
- // This is ridiculous.
+ if (cpuInfo[2] & 0x00000200)
+ flags |= CPUF_SUPPORTS_SSSE3;
- static long CPUCheckForSSESupport() {
- __try {
- // __asm andps xmm0,xmm0
-
- __asm _emit 0x0f
- __asm _emit 0x54
- __asm _emit 0xc0
+ if (cpuInfo[2] & 0x00080000)
+ flags |= CPUF_SUPPORTS_SSE41;
- } __except(EXCEPTION_EXECUTE_HANDLER) {
- if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
- g_lCPUExtensionsAvailable &= ~(CPUF_SUPPORTS_SSE|CPUF_SUPPORTS_SSE2|CPUF_SUPPORTS_SSE3|CPUF_SUPPORTS_SSSE3);
+ // check OSXSAVE and AVX bits
+ if ((cpuInfo[2] & ((1 << 27) | (1 << 28))) == ((1 << 27) | (1 << 28))) {
+ if (VDIsAVXSupportedByOS())
+ flags |= CPUF_SUPPORTS_AVX;
+ }
}
-
- return g_lCPUExtensionsAvailable;
}
- long __declspec(naked) CPUCheckForExtensions() {
- __asm {
- push ebp
- push edi
- push esi
- push ebx
-
- xor ebp,ebp ;cpu flags - if we don't have CPUID, we probably
- ;won't want to try FPU optimizations.
-
- ;check for CPUID.
-
- pushfd ;flags -> EAX
- pop eax
- or eax,00200000h ;set the ID bit
- push eax ;EAX -> flags
- popfd
- pushfd ;flags -> EAX
- pop eax
- and eax,00200000h ;ID bit set?
- jz done ;nope...
-
- ;CPUID exists, check for features register.
-
- mov ebp,00000003h
- xor eax,eax
- cpuid
- or eax,eax
- jz done ;no features register?!?
-
- ;features register exists, look for MMX, SSE, SSE2.
-
- mov eax,1
- cpuid
- mov ebx,edx
- and ebx,00800000h ;MMX is bit 23 of EDX
- shr ebx,21
- or ebp,ebx ;set bit 2 if MMX exists
-
- mov ebx,edx
- and edx,02000000h ;SSE is bit 25 of EDX
- shr edx,25
- neg edx
- and edx,00000018h ;set bits 3 and 4 if SSE exists
- or ebp,edx
-
- and ebx,04000000h ;SSE2 is bit 26 of EDX
- shr ebx,21
- and ebx,00000020h ;set bit 5
- or ebp,ebx
-
- test ecx, 1 ;SSE3 is bit 0 of ECX
- jz no_sse3
- or ebp, 100h
-no_sse3:
-
- test ecx, 200h ;SSSE3 is bit 9 of ECX
- jz no_ssse3
- or ebp, 200h
-no_ssse3:
-
- test ecx, 80000h ;SSE4_1 is bit 19 of ECX
- jz no_sse4_1
- or ebp, 400h
-no_sse4_1:
-
- ;check for vendor feature register (K6/Athlon).
-
- mov eax,80000000h
- cpuid
- mov ecx,80000001h
- cmp eax,ecx
- jb done
-
- ;vendor feature register exists, look for 3DNow! and Athlon extensions
-
- mov eax,ecx
- cpuid
-
- mov eax,edx
- and edx,80000000h ;3DNow! is bit 31
- shr edx,25
- or ebp,edx ;set bit 6
-
- mov edx,eax
- and eax,40000000h ;3DNow!2 is bit 30
- shr eax,23
- or ebp,eax ;set bit 7
-
- and edx,00400000h ;AMD MMX extensions (integer SSE) is bit 22
- shr edx,19
- or ebp,edx
-
- done:
- mov eax,ebp
- mov g_lCPUExtensionsAvailable, ebp
-
- ;Full SSE and SSE-2 require OS support for the xmm* registers.
-
- test eax,00000030h
- jz nocheck
- call CPUCheckForSSESupport
- nocheck:
- pop ebx
- pop esi
- pop edi
- pop ebp
- ret
- }
+ // check for 3DNow!, 3DNow! extensions
+ __cpuid(cpuInfo, 0x80000000);
+ if ((unsigned)cpuInfo[0] >= 0x80000001U) {
+ __cpuid(cpuInfo, 0x80000001);
+
+ if (cpuInfo[3] & (1 << 31))
+ flags |= CPUF_SUPPORTS_3DNOW;
+
+ if (cpuInfo[3] & (1 << 30))
+ flags |= CPUF_SUPPORTS_3DNOW_EXT;
+
+ if (cpuInfo[3] & (1 << 22))
+ flags |= CPUF_SUPPORTS_INTEGER_SSE;
}
-#endif
+ return flags;
+}
long CPUEnableExtensions(long lEnableFlags) {
g_lCPUExtensionsEnabled = lEnableFlags;
diff --git a/src/thirdparty/VirtualDub/system/source/fileasync.cpp b/src/thirdparty/VirtualDub/system/source/fileasync.cpp index 21457879a..03e923a8a 100644 --- a/src/thirdparty/VirtualDub/system/source/fileasync.cpp +++ b/src/thirdparty/VirtualDub/system/source/fileasync.cpp @@ -462,6 +462,7 @@ protected: uint32 mWriteOffset;
VDAtomicInt mBufferLevel;
+ sint64 mClientSlowPointer;
sint64 mClientFastPointer;
sint64 mFastPointer;
@@ -479,6 +480,7 @@ VDFileAsyncNT::VDFileAsyncNT() : mhFileSlow(INVALID_HANDLE_VALUE)
, mhFileFast(INVALID_HANDLE_VALUE)
, mFastPointer(0)
+ , mClientSlowPointer(0)
, mClientFastPointer(0)
, mbPreemptiveExtend(false)
, mpError(NULL)
@@ -645,7 +647,7 @@ void VDFileAsyncNT::Write(sint64 pos, const void *p, uint32 bytes) { Seek(pos);
DWORD dwActual;
- if (!WriteFile(mhFileSlow, p, bytes, &dwActual, NULL) || dwActual != bytes)
+ if (!WriteFile(mhFileSlow, p, bytes, &dwActual, NULL) || (mClientSlowPointer += dwActual),(dwActual != bytes))
throw MyWin32Error("Write error occurred on file \"%s\": %%s", GetLastError(), mFilename.c_str());
}
@@ -707,6 +709,9 @@ void VDFileAsyncNT::Seek(sint64 pos) { }
bool VDFileAsyncNT::SeekNT(sint64 pos) {
+ if (mClientSlowPointer == pos)
+ return true;
+
LONG posHi = (LONG)(pos >> 32);
DWORD result = SetFilePointer(mhFileSlow, (LONG)pos, &posHi, FILE_BEGIN);
@@ -717,6 +722,7 @@ bool VDFileAsyncNT::SeekNT(sint64 pos) { return false;
}
+ mClientSlowPointer = pos;
return true;
}
diff --git a/src/thirdparty/VirtualDub/system/source/int128.cpp b/src/thirdparty/VirtualDub/system/source/int128.cpp index fbc8ece86..082ac1fb6 100644 --- a/src/thirdparty/VirtualDub/system/source/int128.cpp +++ b/src/thirdparty/VirtualDub/system/source/int128.cpp @@ -386,7 +386,7 @@ const vdint128 vdint128::operator*(const vdint128& x) const { bd.q[1] += X.q[0]*Y.q[1] + X.q[1]*Y.q[0];
- return (q[1]^x.q[1])<0 ? -(const vdint128&)bd : (const vdint128&)bd;
+ return (q[1]^x.q[1])<0 ? -vdint128(bd) : vdint128(bd);
}
const vdint128 vdint128::operator/(int x) const {
diff --git a/src/thirdparty/VirtualDub/system/source/zip.cpp b/src/thirdparty/VirtualDub/system/source/zip.cpp index 9b39ed30b..99f5cc861 100644 --- a/src/thirdparty/VirtualDub/system/source/zip.cpp +++ b/src/thirdparty/VirtualDub/system/source/zip.cpp @@ -640,3 +640,92 @@ IVDStream *VDZipArchive::OpenRawStream(sint32 idx) { return mpStream;
}
+
+///////////////////////////////////////////////////////////////////////////
+
+VDGUnzipStream::VDGUnzipStream() {
+}
+
+VDGUnzipStream::VDGUnzipStream(IVDStream *pSrc, uint64 limit) {
+ Init(pSrc, limit);
+}
+
+VDGUnzipStream::~VDGUnzipStream() {
+}
+
+void VDGUnzipStream::Init(IVDStream *pSrc, uint64 limit) {
+ // See RFC1952 for a description of the gzip header format.
+ uint8 hdr[10];
+
+ uint32 gzipContainerBytes = 10 + 8; // header + footer
+ pSrc->Read(hdr, 10);
+ if (hdr[0] != 0x1f || hdr[1] != 0x8b)
+ throw MyError("Source stream is not in gzip format.");
+
+ if (hdr[2] != 0x08)
+ throw MyError("Gzip stream uses an unsupported compression method.");
+
+ enum {
+ FLG_FTEXT = 0x01,
+ FLG_FHCRC = 0x02,
+ FLG_FEXTRA = 0x04,
+ FLG_FNAME = 0x08,
+ FLG_FCOMMENT = 0x10
+ };
+
+ const uint8 flg = hdr[3];
+
+ if (flg & FLG_FEXTRA) {
+ uint8 xlendat[2];
+ pSrc->Read(xlendat, 2);
+
+ uint32 xlen = VDReadUnalignedLEU16(xlendat);
+ uint8 buf[256];
+
+ gzipContainerBytes += xlen + 2;
+
+ while(xlen) {
+ uint32 tc = xlen > 256 ? 256 : xlen;
+ pSrc->Read(buf, tc);
+ xlen -= tc;
+ }
+ }
+
+ if (flg & FLG_FNAME) {
+ // ugh
+ uint8 c;
+ for(;;) {
+ pSrc->Read(&c, 1);
+ ++gzipContainerBytes;
+
+ if (!c)
+ break;
+
+ mFilename += c;
+ }
+ }
+
+ if (flg & FLG_FCOMMENT) {
+ // ugh
+ uint8 c;
+ do {
+ pSrc->Read(&c, 1);
+ ++gzipContainerBytes;
+ } while(c);
+ }
+
+ if (flg & FLG_FHCRC) {
+ uint16 crc16;
+
+ pSrc->Read(&crc16, 2);
+ gzipContainerBytes += 2;
+ }
+
+ if (gzipContainerBytes > limit)
+ throw MyError("The gzip compressed data is invalid.");
+
+ limit -= gzipContainerBytes;
+
+ VDZipStream::Init(pSrc, limit, false);
+}
+
diff --git a/src/thirdparty/VirtualDub/system/system.vcxproj b/src/thirdparty/VirtualDub/system/system.vcxproj index 50e8e0627..09b11f1ae 100644 --- a/src/thirdparty/VirtualDub/system/system.vcxproj +++ b/src/thirdparty/VirtualDub/system/system.vcxproj @@ -223,6 +223,7 @@ <ClInclude Include="..\h\vd2\system\vectors_int.h" />
<ClInclude Include="..\h\vd2\system\w32assist.h" />
<ClInclude Include="..\h\vd2\system\zip.h" />
+ <ClInclude Include="..\h\vd2\system\win32\intrin.h" />
<ClInclude Include="..\h\vd2\system\win32\miniwindows.h" />
<ClInclude Include="h\stdafx.h" />
</ItemGroup>
@@ -233,6 +234,9 @@ <YASM Include="source\a_thunk.asm">
<ExcludedFromBuild Condition="'$(Platform)'=='x64'">true</ExcludedFromBuild>
</YASM>
+ <YASM Include="source\a64_cpuaccel.asm">
+ <ExcludedFromBuild Condition="'$(Platform)'=='Win32'">true</ExcludedFromBuild>
+ </YASM>
<YASM Include="source\a64_fraction.asm">
<ExcludedFromBuild Condition="'$(Platform)'=='Win32'">true</ExcludedFromBuild>
</YASM>
diff --git a/src/thirdparty/VirtualDub/system/system.vcxproj.filters b/src/thirdparty/VirtualDub/system/system.vcxproj.filters index 41673220c..0789c5607 100644 --- a/src/thirdparty/VirtualDub/system/system.vcxproj.filters +++ b/src/thirdparty/VirtualDub/system/system.vcxproj.filters @@ -308,6 +308,9 @@ <ClInclude Include="..\h\vd2\system\zip.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\h\vd2\system\win32\intrin.h">
+ <Filter>Header Files\win32</Filter>
+ </ClInclude>
<ClInclude Include="..\h\vd2\system\win32\miniwindows.h">
<Filter>Header Files\win32</Filter>
</ClInclude>
@@ -346,6 +349,9 @@ <YASM Include="source\a_thunk.asm">
<Filter>Assembly Files %28x86%29</Filter>
</YASM>
+ <YASM Include="source\a64_cpuaccel.asm">
+ <Filter>Assembly Files %28AMD64%29</Filter>
+ </YASM>
<YASM Include="source\a64_fraction.asm">
<Filter>Assembly Files %28AMD64%29</Filter>
</YASM>
|