Skip to content

Commit

Permalink
Update AVS headers and copy frame properties for AVS+ and VS
Browse files Browse the repository at this point in the history
  • Loading branch information
realfinder authored and msg7086 committed May 30, 2021
1 parent 9605825 commit 4091d91
Show file tree
Hide file tree
Showing 8 changed files with 773 additions and 158 deletions.
808 changes: 662 additions & 146 deletions include/avisynth/avisynth.h

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions include/avisynth/avs/capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
#include "config.h"

#ifdef AVS_POSIX
// this is also defined in avs/posix.h, but that header is for the core,
// not external programs
// this is also defined in avs/posix.h
#ifndef AVS_HAIKU
#define __declspec(x)
#endif
#endif

#ifdef __cplusplus
# define EXTERN_C extern "C"
Expand Down Expand Up @@ -93,16 +94,25 @@

#ifdef BUILDING_AVSCORE
#ifdef AVS_WINDOWS
# define AVSC_EXPORT __declspec(dllexport)
# ifndef AVS_STATIC_LIB
# define AVSC_EXPORT __declspec(dllexport)
# else
# define AVSC_EXPORT
# endif
# define AVSC_API(ret, name) EXTERN_C AVSC_EXPORT ret AVSC_CC name
#else
# define AVSC_EXPORT EXTERN_C
# define AVSC_API(ret, name) EXTERN_C ret AVSC_CC name
#endif
#else
# define AVSC_EXPORT EXTERN_C __declspec(dllexport)
# ifndef AVS_STATIC_LIB
# define AVSC_IMPORT __declspec(dllimport)
# else
# define AVSC_IMPORT
# endif
# ifndef AVSC_NO_DECLSPEC
# define AVSC_API(ret, name) EXTERN_C __declspec(dllimport) ret AVSC_CC name
# define AVSC_API(ret, name) EXTERN_C AVSC_IMPORT ret AVSC_CC name
# else
# define AVSC_API(ret, name) typedef ret (AVSC_CC *name##_func)
# endif
Expand Down
56 changes: 53 additions & 3 deletions include/avisynth/avs/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,23 @@
# define X86_64
#elif defined(_M_IX86) || defined(__i386__)
# define X86_32
// VS2017 introduced _M_ARM64
#elif defined(_M_ARM64) || defined(__aarch64__)
# define ARM64
#elif defined(_M_ARM) || defined(__arm__)
# define ARM32
#elif defined(__PPC64__)
# define PPC64
#elif defined(_M_PPC) || defined(__PPC__) || defined(__POWERPC__)
# define PPC32
#else
# error Unsupported CPU architecture.
#endif

// VC++ LLVM-Clang-cl MinGW-Gnu
// MSVC x x
// MSVC x x
// MSVC_PURE x
// CLANG x
// CLANG x
// GCC x

#if defined(__clang__)
Expand All @@ -66,7 +75,6 @@
# define MSVC
# define AVS_FORCEINLINE __attribute__((always_inline))
#else
# define GCC
# define AVS_FORCEINLINE __attribute__((always_inline)) inline
#endif
#elif defined(_MSC_VER)
Expand Down Expand Up @@ -94,12 +102,54 @@
#elif defined(__APPLE__)
# define AVS_MACOS
# define AVS_POSIX
#elif defined(__HAIKU__)
# define AVS_HAIKU
# define AVS_POSIX
#else
# error Operating system unsupported.
#endif

// useful warnings disabler macros for supported compilers

#if defined(_MSC_VER)
#define DISABLE_WARNING_PUSH __pragma(warning( push ))
#define DISABLE_WARNING_POP __pragma(warning( pop ))
#define DISABLE_WARNING(warningNumber) __pragma(warning( disable : warningNumber ))

#define DISABLE_WARNING_UNREFERENCED_LOCAL_VARIABLE DISABLE_WARNING(4101)
#define DISABLE_WARNING_UNREFERENCED_FUNCTION DISABLE_WARNING(4505)
// other warnings you want to deactivate...

#elif defined(__GNUC__) || defined(__clang__)
#define DO_PRAGMA(X) _Pragma(#X)
#define DISABLE_WARNING_PUSH DO_PRAGMA(GCC diagnostic push)
#define DISABLE_WARNING_POP DO_PRAGMA(GCC diagnostic pop)
#define DISABLE_WARNING(warningName) DO_PRAGMA(GCC diagnostic ignored #warningName)

#define DISABLE_WARNING_UNREFERENCED_LOCAL_VARIABLE DISABLE_WARNING(-Wunused-variable)
#define DISABLE_WARNING_UNREFERENCED_FUNCTION DISABLE_WARNING(-Wunused-function)
// other warnings you want to deactivate...

#else
#define DISABLE_WARNING_PUSH
#define DISABLE_WARNING_POP
#define DISABLE_WARNING_UNREFERENCED_LOCAL_VARIABLE
#define DISABLE_WARNING_UNREFERENCED_FUNCTION
// other warnings you want to deactivate...

#endif

#if defined(AVS_POSIX)
#define NEW_AVSVALUE
#else
#define NEW_AVSVALUE
#endif

#if defined(AVS_WINDOWS)
// Windows XP does not have proper initialization for
// thread local variables.
// Use workaround instead __declspec(thread)
#define XP_TLS
#endif

#endif //AVS_CONFIG_H
3 changes: 2 additions & 1 deletion include/avisynth/avs/cpuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ enum {
CPUF_SSE3 = 0x100, // PIV+, K8 Venice
CPUF_SSSE3 = 0x200, // Core 2
CPUF_SSE4 = 0x400,
CPUF_SSE4_1 = 0x400, // Penryn, Wolfdale, Yorkfield
CPUF_SSE4_1 = 0x400, // Penryn, Wolfdale, Yorkfield
CPUF_AVX = 0x800, // Sandy Bridge, Bulldozer
CPUF_SSE4_2 = 0x1000, // Nehalem
// AVS+
Expand All @@ -75,6 +75,7 @@ enum {

#ifdef BUILDING_AVSCORE
int GetCPUFlags();
void SetMaxCPU(int new_flags);
#endif

#endif // AVSCORE_CPUID_H
15 changes: 15 additions & 0 deletions include/avisynth/avs/filesystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

// Snippet copied from filesystem/README.md

#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include)
#if __has_include(<filesystem>)
#define GHC_USE_STD_FS
#include <filesystem>
namespace fs = std::filesystem;
#endif
#endif
#ifndef GHC_USE_STD_FS
#include <ghc/filesystem.hpp>
namespace fs = ghc::filesystem;
#endif
18 changes: 18 additions & 0 deletions include/avisynth/avs/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
#define __single_inheritance

// These things don't exist in Linux
#if defined(AVS_HAIKU)
#undef __declspec
#endif
#define __declspec(x)
#define lstrlen strlen
#define lstrcmp strcmp
Expand Down Expand Up @@ -104,8 +107,23 @@
#define STATUS_STACK_OVERFLOW 0xc00000fd

// Calling convension
#ifndef AVS_HAIKU
#define __stdcall
#define __cdecl
#endif

// PowerPC OS X is really niche these days, but this painless equivocation
// of the function/macro names used in posix_get_available_memory()
// is all it takes to let it work. The G5 was 64-bit, and if 10.5 Leopard
// can run in native 64-bit, it probably uses the names in that block as-is.
#ifdef AVS_MACOS
#ifdef PPC32
#define vm_statistics64_data_t vm_statistics_data_t
#define HOST_VM_INFO64_COUNT HOST_VM_INFO_COUNT
#define HOST_VM_INFO64 HOST_VM_INFO
#define host_statistics64 host_statistics
#endif // PPC32
#endif // AVS_MACOS

#endif // AVSCORE_POSIX_H
#endif // AVS_POSIX
2 changes: 2 additions & 0 deletions include/avisynth/avs/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
#include <stdbool.h>
#ifdef __cplusplus
#include <cstddef>
#include <cstdarg>
#else
#include <stddef.h>
#include <stdarg.h>
#endif

// Raster types used by VirtualDub & Avisynth
Expand Down
11 changes: 7 additions & 4 deletions include/dualsynth/ds_frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ struct DSFrame
const VSFrameRef* copy_frames[1] {ToVSFrame()};
int copy_planes[4] = {0};
auto vsframe = copy ?
_vsapi->newVideoFrame2(_vsformat, FrameWidth, FrameHeight, copy_frames, copy_planes, NULL, const_cast<VSCore*>(_vscore)) :
_vsapi->newVideoFrame(_vsformat, FrameWidth, FrameHeight, NULL, const_cast<VSCore*>(_vscore));
_vsapi->newVideoFrame2(_vsformat, FrameWidth, FrameHeight, copy_frames, copy_planes, ToVSFrame(), const_cast<VSCore*>(_vscore)) :
_vsapi->newVideoFrame(_vsformat, FrameWidth, FrameHeight, ToVSFrame(), const_cast<VSCore*>(_vscore));
_vsapi->freeFrame(copy_frames[0]);

DSFrame new_frame(vsframe, _vscore, _vsapi);
Expand All @@ -101,7 +101,7 @@ struct DSFrame
DSFrame Create(DSVideoInfo vi) {
planes = vi.Format.IsFamilyYUV ? planes_y : planes_r;
if (_vsapi) {
auto vsframe = _vsapi->newVideoFrame(vi.Format.ToVSFormat(_vscore, _vsapi), vi.Width, vi.Height, NULL, const_cast<VSCore*>(_vscore));
auto vsframe = _vsapi->newVideoFrame(vi.Format.ToVSFormat(_vscore, _vsapi), vi.Width, vi.Height, ToVSFrame(), const_cast<VSCore*>(_vscore));
DSFrame new_frame(vsframe, _vscore, _vsapi);
new_frame._vsdst = vsframe;
new_frame.DstPointers = new unsigned char*[Format.Planes];
Expand All @@ -111,7 +111,10 @@ struct DSFrame
}
else if (_env) {
auto avsvi = vi.ToAVSVI();
auto new_avsframe = _env->NewVideoFrame(avsvi);
bool has_at_least_v8 = true;
try { _env->CheckVersion(8); }
catch (const AvisynthError&) { has_at_least_v8 = false; }
auto new_avsframe = (has_at_least_v8) ? _env->NewVideoFrameP(avsvi, &_avssrc) : _env->NewVideoFrame(avsvi);
auto dstp = new unsigned char*[Format.Planes];
for (int i = 0; i < Format.Planes; i++)
dstp[i] = new_avsframe->GetWritePtr(planes[i]);
Expand Down

0 comments on commit 4091d91

Please sign in to comment.