From patchwork Wed Mar 11 10:50:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hutchinson X-Patchwork-Id: 18120 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id B0FC1449CB2 for ; Wed, 11 Mar 2020 12:56:25 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 908D668AE26; Wed, 11 Mar 2020 12:56:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw1-f53.google.com (mail-yw1-f53.google.com [209.85.161.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 706E5687F66 for ; Wed, 11 Mar 2020 12:56:18 +0200 (EET) Received: by mail-yw1-f53.google.com with SMTP id d206so1508378ywa.12 for ; Wed, 11 Mar 2020 03:56:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=lHqoQfhlo0fWfWmHF70EZH2ekDoBeZrW644O97Qi5tY=; b=gEO5PepY90xvyo8Ukcd8w05aMERdD0TG7p0GTx6L12VUXOuaEmkLTiUizkO5QRTQXa RrpbqwoLV+AtWfmxvwexTMd8QXlBjJr5L7tTgbcj4nRBwwQ5RuqotExzvOQ6TbwrLPUH SVhzktZwaJN6uZNodXn3fBdqvMKfZB7LHzOs/pM1mDUvqKekIKc9jmQ3AAaXMPEsg+3J 3v7qn/A5Ut7CQUn8TiktELtdErw0rZg7lkjZZTV9TW9HVQ/OTYAznivnkFCwG1gVmzCq y8UH8rqFfUH/CSthoDb1z8WQmNuY2H6LHRUqpi4QNWvHQOHAUwCVRnOocdf8j5xE0dXC GU8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lHqoQfhlo0fWfWmHF70EZH2ekDoBeZrW644O97Qi5tY=; b=ANhmKqf5QaPiXvY8yhk0Nx9txM9JtfdYoY17h6mBTVPmVv1+uMTOTfGNrfvXutz357 UBe/tYZc8ACsrb6WPZAlyOULYOSVMuUxDMjITqTYXwYRpwMc3vWtTW/jcStjyEI4oZ7y eXQFYCVAT+Egqv2bg40aZhMapmSMozKUKg21qt/FE6vpA1PCAo+U0qEV8Y3thrcZLDuH VT7/KEHo1MjkMkyGREIUkpBCzaYVX9Z0USZzF2KIZXjfOlwMWME8AXO4Ioo9VAAdZm4a gvgTBGKkJi4JUqxW0GjMQQ5s2M4BtBwAUDHRyLWpE0EzDmiOJygFjqNcX7unjbz5+sGL QcRA== X-Gm-Message-State: ANhLgQ0T1Z9n75VEsA+ge+xv9fNBv8nR4thCPTZjd7spbY9ODIPdFhdw o85NUHo3wZ1mHUtARj2HY2A0TwTo X-Google-Smtp-Source: ADFU+vtjpO8oTGgdkVKqLF9lL4cgjLQwIbMSKEAvbF1kl2MpG3f0fXMt43ca+AifV7ufIpXLDQz8QA== X-Received: by 2002:a0d:dcc7:: with SMTP id f190mr2468969ywe.193.1583923826089; Wed, 11 Mar 2020 03:50:26 -0700 (PDT) Received: from localhost.localdomain ([75.115.109.114]) by smtp.gmail.com with ESMTPSA id t186sm4344839ywb.37.2020.03.11.03.50.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2020 03:50:25 -0700 (PDT) From: Stephen Hutchinson To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 Mar 2020 06:50:15 -0400 Message-Id: <20200311105019.8553-2-qyot27@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200311105019.8553-1-qyot27@gmail.com> References: <20200311105019.8553-1-qyot27@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] compat/avisynth: update headers X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" AviSynth+ can now be used on Linux, which required some changes to the headers. --- compat/avisynth/avisynth_c.h | 24 ++++---- compat/avisynth/avs/capi.h | 16 +++++ compat/avisynth/avs/config.h | 46 +++++++++++++-- compat/avisynth/avs/posix.h | 111 +++++++++++++++++++++++++++++++++++ compat/avisynth/avs/types.h | 13 ++-- 5 files changed, 185 insertions(+), 25 deletions(-) create mode 100644 compat/avisynth/avs/posix.h diff --git a/compat/avisynth/avisynth_c.h b/compat/avisynth/avisynth_c.h index 9ff9321552..03c3530ca9 100644 --- a/compat/avisynth/avisynth_c.h +++ b/compat/avisynth/avisynth_c.h @@ -341,7 +341,7 @@ typedef struct AVS_VideoInfo { int audio_samples_per_second; // 0 means no audio int sample_type; - INT64 num_audio_samples; + int64_t num_audio_samples; int nchannels; // Image type properties @@ -444,16 +444,16 @@ AVSC_INLINE int avs_bytes_per_channel_sample(const AVS_VideoInfo * p) AVSC_INLINE int avs_bytes_per_audio_sample(const AVS_VideoInfo * p) { return p->nchannels*avs_bytes_per_channel_sample(p);} -AVSC_INLINE INT64 avs_audio_samples_from_frames(const AVS_VideoInfo * p, INT64 frames) - { return ((INT64)(frames) * p->audio_samples_per_second * p->fps_denominator / p->fps_numerator); } +AVSC_INLINE int64_t avs_audio_samples_from_frames(const AVS_VideoInfo * p, int64_t frames) + { return ((int64_t)(frames) * p->audio_samples_per_second * p->fps_denominator / p->fps_numerator); } -AVSC_INLINE int avs_frames_from_audio_samples(const AVS_VideoInfo * p, INT64 samples) - { return (int)(samples * (INT64)p->fps_numerator / (INT64)p->fps_denominator / (INT64)p->audio_samples_per_second); } +AVSC_INLINE int avs_frames_from_audio_samples(const AVS_VideoInfo * p, int64_t samples) + { return (int)(samples * (int64_t)p->fps_numerator / (int64_t)p->fps_denominator / (int64_t)p->audio_samples_per_second); } -AVSC_INLINE INT64 avs_audio_samples_from_bytes(const AVS_VideoInfo * p, INT64 bytes) +AVSC_INLINE int64_t avs_audio_samples_from_bytes(const AVS_VideoInfo * p, int64_t bytes) { return bytes / avs_bytes_per_audio_sample(p); } -AVSC_INLINE INT64 avs_bytes_from_audio_samples(const AVS_VideoInfo * p, INT64 samples) +AVSC_INLINE int64_t avs_bytes_from_audio_samples(const AVS_VideoInfo * p, int64_t samples) { return samples * avs_bytes_per_audio_sample(p); } AVSC_INLINE int avs_audio_channels(const AVS_VideoInfo * p) @@ -764,7 +764,7 @@ AVSC_API(int, avs_get_parity)(AVS_Clip *, int n); // return field parity if field_based, else parity of first field in frame AVSC_API(int, avs_get_audio)(AVS_Clip *, void * buf, - INT64 start, INT64 count); + int64_t start, int64_t count); // start and count are in samples AVSC_API(int, avs_set_cache_hints)(AVS_Clip *, @@ -784,7 +784,7 @@ struct AVS_FilterInfo AVS_VideoFrame * (AVSC_CC * get_frame)(AVS_FilterInfo *, int n); int (AVSC_CC * get_parity)(AVS_FilterInfo *, int n); int (AVSC_CC * get_audio)(AVS_FilterInfo *, void * buf, - INT64 start, INT64 count); + int64_t start, int64_t count); int (AVSC_CC * set_cache_hints)(AVS_FilterInfo *, int cachehints, int frame_range); void (AVSC_CC * free_filter)(AVS_FilterInfo *); @@ -933,6 +933,8 @@ AVSC_API(void, avs_delete_script_environment)(AVS_ScriptEnvironment *); AVSC_API(AVS_VideoFrame *, avs_subframe_planar)(AVS_ScriptEnvironment *, AVS_VideoFrame * src, int rel_offset, int new_pitch, int new_row_size, int new_height, int rel_offsetU, int rel_offsetV, int new_pitchUV); // The returned video frame must be be released +#if defined(AVS_WINDOWS) +// The following stuff is only relevant for Windows DLL handling; Linux does it completely differently. #ifdef AVSC_NO_DECLSPEC // This part uses LoadLibrary and related functions to dynamically load Avisynth instead of declspec(dllimport) // When AVSC_NO_DECLSPEC is defined, you can use avs_load_library to populate API functions into a struct @@ -944,7 +946,7 @@ AVSC_API(AVS_VideoFrame *, avs_subframe_planar)(AVS_ScriptEnvironment *, AVS_Vid void* malloc(size_t) void free(void*); - HMODULE LoadLibrary(const char*); + HMODULE LoadLibraryA(const char*); void* GetProcAddress(HMODULE, const char*); FreeLibrary(HMODULE); */ @@ -1261,4 +1263,6 @@ AVSC_INLINE void avs_free_library(AVS_Library *library) { } #endif +#endif // AVS_WINDOWS + #endif diff --git a/compat/avisynth/avs/capi.h b/compat/avisynth/avs/capi.h index 8799bf1fbb..4e31a5de48 100644 --- a/compat/avisynth/avs/capi.h +++ b/compat/avisynth/avs/capi.h @@ -33,12 +33,20 @@ #ifndef AVS_CAPI_H #define AVS_CAPI_H +#include "config.h" + +#ifdef AVS_POSIX +// this is also defined in avs/posix.h +#define __declspec(x) +#endif + #ifdef __cplusplus # define EXTERN_C extern "C" #else # define EXTERN_C #endif +#ifdef AVS_WINDOWS #ifdef BUILDING_AVSCORE # if defined(GCC) && defined(X86_32) # define AVSC_CC @@ -60,6 +68,9 @@ # define AVSC_CC # endif #endif +# else +# define AVSC_CC +#endif // On 64-bit Windows, there's only one calling convention, // so there is no difference between MSVC and GCC. On 32-bit, @@ -80,9 +91,14 @@ #define AVSC_INLINE static __inline #ifdef BUILDING_AVSCORE +#ifdef AVS_WINDOWS # define AVSC_EXPORT __declspec(dllexport) # 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 AVSC_NO_DECLSPEC # define AVSC_API(ret, name) EXTERN_C __declspec(dllimport) ret AVSC_CC name diff --git a/compat/avisynth/avs/config.h b/compat/avisynth/avs/config.h index a7d3e692ea..896dae20ff 100644 --- a/compat/avisynth/avs/config.h +++ b/compat/avisynth/avs/config.h @@ -52,19 +52,53 @@ # error Unsupported CPU architecture. #endif -#if defined(_MSC_VER) +// VC++ LLVM-Clang-cl MinGW-Gnu +// MSVC x x +// MSVC_PURE x +// CLANG x +// GCC x + +#if defined(__clang__) +// Check clang first. clang-cl also defines __MSC_VER +// We set MSVC because they are mostly compatible +# define CLANG +#if defined(_MSC_VER) # define MSVC +# define AVS_FORCEINLINE __attribute__((always_inline)) +#else +# define AVS_FORCEINLINE __attribute__((always_inline)) inline +#endif +#elif defined(_MSC_VER) +# define MSVC +# define MSVC_PURE +# define AVS_FORCEINLINE __forceinline #elif defined(__GNUC__) # define GCC -#elif defined(__clang__) -# define CLANG +# define AVS_FORCEINLINE __attribute__((always_inline)) inline #else # error Unsupported compiler. -#endif - -#if defined(GCC) +# define AVS_FORCEINLINE inline # undef __forceinline # define __forceinline inline #endif +#if defined(_WIN32) +# define AVS_WINDOWS +#elif defined(__linux__) +# define AVS_LINUX +# define AVS_POSIX +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) +# define AVS_BSD +# define AVS_POSIX +#elif defined(__APPLE__) +# define AVS_MACOS +# define AVS_POSIX +#else +# error Operating system unsupported. +#endif + +#if defined(AVS_POSIX) +#define NEW_AVSVALUE +#endif + #endif //AVS_CONFIG_H diff --git a/compat/avisynth/avs/posix.h b/compat/avisynth/avs/posix.h new file mode 100644 index 0000000000..9c938b26ea --- /dev/null +++ b/compat/avisynth/avs/posix.h @@ -0,0 +1,111 @@ +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit +// http://www.gnu.org/copyleft/gpl.html . +// +// Linking Avisynth statically or dynamically with other modules is making a +// combined work based on Avisynth. Thus, the terms and conditions of the GNU +// General Public License cover the whole combination. +// +// As a special exception, the copyright holders of Avisynth give you +// permission to link Avisynth with independent modules that communicate with +// Avisynth solely through the interfaces defined in avisynth.h, regardless of the license +// terms of these independent modules, and to copy and distribute the +// resulting combined work under terms of your choice, provided that +// every copy of the combined work is accompanied by a complete copy of +// the source code of Avisynth (the version of Avisynth used to produce the +// combined work), being distributed under the terms of the GNU General +// Public License plus this exception. An independent module is a module +// which is not derived from or based on Avisynth, such as 3rd-party filters, +// import and export plugins, or graphical user interfaces. + +#ifdef AVS_POSIX +#ifndef AVSCORE_POSIX_H +#define AVSCORE_POSIX_H + +#ifdef __cplusplus +#include +#endif +#include +#include + +// Define these MSVC-extension used in Avisynth +#define __single_inheritance + +// These things don't exist in Linux +#define __declspec(x) +#define lstrlen strlen +#define lstrcmp strcmp +#define lstrcmpi strcasecmp +#define _stricmp strcasecmp +#define _strnicmp strncasecmp +#define _strdup strdup +#define SetCurrentDirectory(x) chdir(x) +#define SetCurrentDirectoryW(x) chdir(x) +#define GetCurrentDirectoryW(x) getcwd(x) +#define _putenv putenv +#define _alloca alloca + +// Borrowing some compatibility macros from AvxSynth, slightly modified +#define UInt32x32To64(a, b) ((uint64_t)(((uint64_t)((uint32_t)(a))) * ((uint32_t)(b)))) +#define Int64ShrlMod32(a, b) ((uint64_t)((uint64_t)(a) >> (b))) +#define Int32x32To64(a, b) ((int64_t)(((int64_t)((long)(a))) * ((long)(b)))) + +#define InterlockedIncrement(x) __sync_add_and_fetch((x), 1) +#define InterlockedDecrement(x) __sync_sub_and_fetch((x), 1) +#define MulDiv(nNumber, nNumerator, nDenominator) (int32_t) (((int64_t) (nNumber) * (int64_t) (nNumerator) + (int64_t) ((nDenominator)/2)) / (int64_t) (nDenominator)) + +#ifndef TRUE +#define TRUE true +#endif + +#ifndef FALSE +#define FALSE false +#endif + +#define S_FALSE (0x00000001) +#define E_FAIL (0x80004005) +#define FAILED(hr) ((hr) & 0x80000000) +#define SUCCEEDED(hr) (!FAILED(hr)) + +// Statuses copied from comments in exception.cpp +#define STATUS_GUARD_PAGE_VIOLATION 0x80000001 +#define STATUS_DATATYPE_MISALIGNMENT 0x80000002 +#define STATUS_BREAKPOINT 0x80000003 +#define STATUS_SINGLE_STEP 0x80000004 +#define STATUS_ACCESS_VIOLATION 0xc0000005 +#define STATUS_IN_PAGE_ERROR 0xc0000006 +#define STATUS_INVALID_HANDLE 0xc0000008 +#define STATUS_NO_MEMORY 0xc0000017 +#define STATUS_ILLEGAL_INSTRUCTION 0xc000001d +#define STATUS_NONCONTINUABLE_EXCEPTION 0xc0000025 +#define STATUS_INVALID_DISPOSITION 0xc0000026 +#define STATUS_ARRAY_BOUNDS_EXCEEDED 0xc000008c +#define STATUS_FLOAT_DENORMAL_OPERAND 0xc000008d +#define STATUS_FLOAT_DIVIDE_BY_ZERO 0xc000008e +#define STATUS_FLOAT_INEXACT_RESULT 0xc000008f +#define STATUS_FLOAT_INVALID_OPERATION 0xc0000090 +#define STATUS_FLOAT_OVERFLOW 0xc0000091 +#define STATUS_FLOAT_STACK_CHECK 0xc0000092 +#define STATUS_FLOAT_UNDERFLOW 0xc0000093 +#define STATUS_INTEGER_DIVIDE_BY_ZERO 0xc0000094 +#define STATUS_INTEGER_OVERFLOW 0xc0000095 +#define STATUS_PRIVILEGED_INSTRUCTION 0xc0000096 +#define STATUS_STACK_OVERFLOW 0xc00000fd + +// Calling convension +#define __stdcall +#define __cdecl + +#endif // AVSCORE_POSIX_H +#endif // AVS_POSIX diff --git a/compat/avisynth/avs/types.h b/compat/avisynth/avs/types.h index df15f1d8e5..ba451c6fae 100644 --- a/compat/avisynth/avs/types.h +++ b/compat/avisynth/avs/types.h @@ -34,7 +34,8 @@ #define AVS_TYPES_H // Define all types necessary for interfacing with avisynth.dll - +#include +#include #ifdef __cplusplus #include #else @@ -42,16 +43,10 @@ #endif // Raster types used by VirtualDub & Avisynth -typedef unsigned int Pixel32; -typedef unsigned char BYTE; +typedef uint32_t Pixel32; +typedef uint8_t BYTE; // Audio Sample information typedef float SFLOAT; -#ifdef __GNUC__ -typedef long long int INT64; -#else -typedef __int64 INT64; -#endif - #endif //AVS_TYPES_H