From a0846a75fdac01df21161ff4d76371544fab4c1a Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Sun, 16 May 2010 21:57:58 +0000 Subject: arithmetic solution on bit level for AVERROR_SIGN. Delphi cannot handle the solution with directives. Still needs check on powerpc. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2377 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/lib/ffmpeg/avcodec.pas | 20 ++++++++++++++------ src/lib/ffmpeg/avutil.pas | 26 +++++++++++++++----------- 2 files changed, 29 insertions(+), 17 deletions(-) (limited to 'src/lib') diff --git a/src/lib/ffmpeg/avcodec.pas b/src/lib/ffmpeg/avcodec.pas index 175ed053..2c98f8fa 100644 --- a/src/lib/ffmpeg/avcodec.pas +++ b/src/lib/ffmpeg/avcodec.pas @@ -4693,13 +4693,21 @@ const {$ENDIF} {$ENDIF} +(** + * We need the sign of of the error, because some platforms have + * E* and errno already negated. The previous version failed + * with Delphi, because it needs EINVAL defined. + * Warning: This code is platform dependent and assumes constants + * to be 32 bit. + * This version does the following steps: + * 1) shr 6: shifts the sign bit to bit position 2 + * 2) and $00000002: sets all other bits to zero + * positive EINVAL gives 0, negative gives 2 + * 3) not: inverts all bits. This gives -1 and -3 + * 4) + 2: positive EINVAL gives 1, negative -1 + *) const -{$IF EINVAL > 0} - AVERROR_SIGN = -1; -{$ELSE} - {* Some platforms have E* and errno already negated. *} - AVERROR_SIGN = 1; -{$IFEND} + AVERROR_SIGN = not((EINVAL shr 6) and $00000002) + 2; (* #if EINVAL > 0 diff --git a/src/lib/ffmpeg/avutil.pas b/src/lib/ffmpeg/avutil.pas index 385b7e3d..0ad7dd31 100644 --- a/src/lib/ffmpeg/avutil.pas +++ b/src/lib/ffmpeg/avutil.pas @@ -161,10 +161,6 @@ type (* libavutil/error.h *) {$IF LIBAVUTIL_VERSION >= 50012000} // >= 50.12.0 - {$DEFINE NEED_ERRORS_HERE} -{$IFEND} - -{$IFDEF NEED_ERRORS_HERE} {* error handling *} @@ -193,13 +189,21 @@ const {$ENDIF} {$ENDIF} +(** + * We need the sign of of the error, because some platforms have + * E* and errno already negated. The previous version failed + * with Delphi, because it needs EINVAL defined. + * Warning: This code is platform dependent and assumes constants + * to be 32 bit. + * This version does the following steps: + * 1) shr 6: shifts the sign bit to bit position 2 + * 2) and $00000002: sets all other bits to zero + * positive EINVAL gives 0, negative gives 2 + * 3) not: inverts all bits. This gives -1 and -3 + * 4) + 2: positive EINVAL gives 1, negative -1 + *) const -{$IF EINVAL > 0} - AVERROR_SIGN = -1; -{$ELSE} - {* Some platforms have E* and errno already negated. *} - AVERROR_SIGN = 1; -{$IFEND} + AVERROR_SIGN = not((EINVAL shr 6) and $00000002) + 2; (* #if EINVAL > 0 @@ -227,7 +231,7 @@ const // Note: function calls as constant-initializers are invalid //AVERROR_PATCHWELCOME = -MKTAG('P','A','W','E'); {**< Not yet implemented in FFmpeg. Patches welcome. *} AVERROR_PATCHWELCOME = -(ord('P') or (ord('A') shl 8) or (ord('W') shl 16) or (ord('E') shl 24)); -{$ENDIF} +{$IFEND} {$IF LIBAVUTIL_VERSION >= 50013000} // >= 50.13.0 (* -- cgit v1.2.3