From 34c63b4991a3feb18b611aa211d0fcb59254fcea Mon Sep 17 00:00:00 2001 From: luvletter2333 Date: Sun, 31 Oct 2021 23:06:27 +0800 Subject: [PATCH] Fix ffmpeg build --- .../ffmpeg/0002-compilation-magic-2.patch | 577 ++++++++++++++++++ 1 file changed, 577 insertions(+) create mode 100644 TMessagesProj/jni/patches/ffmpeg/0002-compilation-magic-2.patch diff --git a/TMessagesProj/jni/patches/ffmpeg/0002-compilation-magic-2.patch b/TMessagesProj/jni/patches/ffmpeg/0002-compilation-magic-2.patch new file mode 100644 index 000000000..95b8244cc --- /dev/null +++ b/TMessagesProj/jni/patches/ffmpeg/0002-compilation-magic-2.patch @@ -0,0 +1,577 @@ +From cdc55ea354ab977ea2f94ea74fad0561b3a8fd93 Mon Sep 17 00:00:00 2001 +From: thermatk +Date: Sat, 26 Jun 2021 16:56:55 +0200 +Subject: [PATCH] [PATCH] Compilation magic 2 + +--- + libavcodec/get_bits.h | 221 ++-------------------------------- + libavcodec/golomb.h | 269 ------------------------------------------ + 2 files changed, 13 insertions(+), 477 deletions(-) + +diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h +index 66fb877..a0695d3 100644 +--- a/libavcodec/get_bits.h ++++ b/libavcodec/get_bits.h +@@ -29,13 +29,9 @@ + + #include + +-#include "libavutil/common.h" +-#include "libavutil/intreadwrite.h" +-#include "libavutil/log.h" +-#include "libavutil/avassert.h" +-#include "avcodec.h" +-#include "mathops.h" +-#include "vlc.h" ++#ifndef NEG_USR32 ++# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) ++#endif + + /* + * Safe bitstream reading: +@@ -313,66 +309,6 @@ static inline void skip_remaining(GetBitContext *s, unsigned n) + } + #endif + +-/** +- * Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB). +- * if MSB not set it is negative +- * @param n length in bits +- */ +-static inline int get_xbits(GetBitContext *s, int n) +-{ +-#if CACHED_BITSTREAM_READER +- int32_t cache = show_bits(s, 32); +- int sign = ~cache >> 31; +- skip_remaining(s, n); +- +- return ((((uint32_t)(sign ^ cache)) >> (32 - n)) ^ sign) - sign; +-#else +- register int sign; +- register int32_t cache; +- OPEN_READER(re, s); +- av_assert2(n>0 && n<=25); +- UPDATE_CACHE(re, s); +- cache = GET_CACHE(re, s); +- sign = ~cache >> 31; +- LAST_SKIP_BITS(re, s, n); +- CLOSE_READER(re, s); +- return (NEG_USR32(sign ^ cache, n) ^ sign) - sign; +-#endif +-} +- +-#if !CACHED_BITSTREAM_READER +-static inline int get_xbits_le(GetBitContext *s, int n) +-{ +- register int sign; +- register int32_t cache; +- OPEN_READER(re, s); +- av_assert2(n>0 && n<=25); +- UPDATE_CACHE_LE(re, s); +- cache = GET_CACHE(re, s); +- sign = sign_extend(~cache, n) >> 31; +- LAST_SKIP_BITS(re, s, n); +- CLOSE_READER(re, s); +- return (zero_extend(sign ^ cache, n) ^ sign) - sign; +-} +-#endif +- +-static inline int get_sbits(GetBitContext *s, int n) +-{ +- register int tmp; +-#if CACHED_BITSTREAM_READER +- av_assert2(n>0 && n<=25); +- tmp = sign_extend(get_bits(s, n), n); +-#else +- OPEN_READER(re, s); +- av_assert2(n>0 && n<=25); +- UPDATE_CACHE(re, s); +- tmp = SHOW_SBITS(re, s, n); +- LAST_SKIP_BITS(re, s, n); +- CLOSE_READER(re, s); +-#endif +- return tmp; +-} +- + /** + * Read 1-25 bits. + */ +@@ -409,61 +345,6 @@ static inline unsigned int get_bits(GetBitContext *s, int n) + return tmp; + } + +-/** +- * Read 0-25 bits. +- */ +-static av_always_inline int get_bitsz(GetBitContext *s, int n) +-{ +- return n ? get_bits(s, n) : 0; +-} +- +-static inline unsigned int get_bits_le(GetBitContext *s, int n) +-{ +-#if CACHED_BITSTREAM_READER +- av_assert2(n>0 && n<=32); +- if (n > s->bits_left) { +- refill_32(s, 1); +- if (s->bits_left < 32) +- s->bits_left = n; +- } +- +- return get_val(s, n, 1); +-#else +- register int tmp; +- OPEN_READER(re, s); +- av_assert2(n>0 && n<=25); +- UPDATE_CACHE_LE(re, s); +- tmp = SHOW_UBITS_LE(re, s, n); +- LAST_SKIP_BITS(re, s, n); +- CLOSE_READER(re, s); +- return tmp; +-#endif +-} +- +-/** +- * Show 1-25 bits. +- */ +-static inline unsigned int show_bits(GetBitContext *s, int n) +-{ +- register unsigned int tmp; +-#if CACHED_BITSTREAM_READER +- if (n > s->bits_left) +-#ifdef BITSTREAM_READER_LE +- refill_32(s, 1); +-#else +- refill_32(s, 0); +-#endif +- +- tmp = show_val(s, n); +-#else +- OPEN_READER_NOSIZE(re, s); +- av_assert2(n>0 && n<=25); +- UPDATE_CACHE(re, s); +- tmp = SHOW_UBITS(re, s, n); +-#endif +- return tmp; +-} +- + static inline void skip_bits(GetBitContext *s, int n) + { + #if CACHED_BITSTREAM_READER +@@ -530,11 +411,6 @@ static inline unsigned int get_bits1(GetBitContext *s) + #endif + } + +-static inline unsigned int show_bits1(GetBitContext *s) +-{ +- return show_bits(s, 1); +-} +- + static inline void skip_bits1(GetBitContext *s) + { + skip_bits(s, 1); +@@ -584,31 +460,6 @@ static inline uint64_t get_bits64(GetBitContext *s, int n) + } + } + +-/** +- * Read 0-32 bits as a signed integer. +- */ +-static inline int get_sbits_long(GetBitContext *s, int n) +-{ +- // sign_extend(x, 0) is undefined +- if (!n) +- return 0; +- +- return sign_extend(get_bits_long(s, n), n); +-} +- +-/** +- * Show 0-32 bits. +- */ +-static inline unsigned int show_bits_long(GetBitContext *s, int n) +-{ +- if (n <= MIN_CACHE_BITS) { +- return show_bits(s, n); +- } else { +- GetBitContext gb = *s; +- return get_bits_long(&gb, n); +- } +-} +- + static inline int check_marker(void *logctx, GetBitContext *s, const char *msg) + { + int bit = get_bits1(s); +@@ -772,62 +623,6 @@ static inline const uint8_t *align_get_bits(GetBitContext *s) + SKIP_BITS(name, gb, n); \ + } while (0) + +-/* Return the LUT element for the given bitstream configuration. */ +-static inline int set_idx(GetBitContext *s, int code, int *n, int *nb_bits, +- VLC_TYPE (*table)[2]) +-{ +- unsigned idx; +- +- *nb_bits = -*n; +- idx = show_bits(s, *nb_bits) + code; +- *n = table[idx][1]; +- +- return table[idx][0]; +-} +- +-/** +- * Parse a vlc code. +- * @param bits is the number of bits which will be read at once, must be +- * identical to nb_bits in init_vlc() +- * @param max_depth is the number of times bits bits must be read to completely +- * read the longest vlc code +- * = (max_vlc_length + bits - 1) / bits +- * @returns the code parsed or -1 if no vlc matches +- */ +-static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], +- int bits, int max_depth) +-{ +-#if CACHED_BITSTREAM_READER +- int nb_bits; +- unsigned idx = show_bits(s, bits); +- int code = table[idx][0]; +- int n = table[idx][1]; +- +- if (max_depth > 1 && n < 0) { +- skip_remaining(s, bits); +- code = set_idx(s, code, &n, &nb_bits, table); +- if (max_depth > 2 && n < 0) { +- skip_remaining(s, nb_bits); +- code = set_idx(s, code, &n, &nb_bits, table); +- } +- } +- skip_remaining(s, n); +- +- return code; +-#else +- int code; +- +- OPEN_READER(re, s); +- UPDATE_CACHE(re, s); +- +- GET_VLC(code, re, s, table, bits, max_depth); +- +- CLOSE_READER(re, s); +- +- return code; +-#endif +-} +- + static inline int decode012(GetBitContext *gb) + { + int n; +@@ -865,4 +660,14 @@ static inline int skip_1stop_8data_bits(GetBitContext *gb) + return 0; + } + ++static inline unsigned int show_bits_long(GetBitContext *s, int n) ++{ ++ if (n <= MIN_CACHE_BITS) { ++ return show_bits(s, n); ++ } else { ++ GetBitContext gb = *s; ++ return get_bits_long(&gb, n); ++ } ++} ++ + #endif /* AVCODEC_GET_BITS_H */ +diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h +index 7fd46a9..637111a 100644 +--- a/libavcodec/golomb.h ++++ b/libavcodec/golomb.h +@@ -33,7 +33,6 @@ + #include + + #include "get_bits.h" +-#include "put_bits.h" + + #define INVALID_VLC 0x80000000 + +@@ -422,144 +421,6 @@ static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, + #endif + } + +-/** +- * read unsigned golomb rice code (jpegls). +- */ +-static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, +- int esc_len) +-{ +- unsigned int buf; +- int log; +- +-#if CACHED_BITSTREAM_READER +- buf = show_bits_long(gb, 32); +- +- log = av_log2(buf); +- +- if (log - k >= 1 && 32 - log < limit) { +- buf >>= log - k; +- buf += (30 - log) << k; +- skip_bits_long(gb, 32 + k - log); +- +- return buf; +- } else { +- int i; +- for (i = 0; +- i < limit && get_bits1(gb) == 0 && get_bits_left(gb) > 0; +- i++); +- +- if (i < limit - 1) { +- buf = get_bits_long(gb, k); +- +- return buf + (i << k); +- } else if (i == limit - 1) { +- buf = get_bits_long(gb, esc_len); +- +- return buf + 1; +- } else +- return -1; +- } +-#else +- OPEN_READER(re, gb); +- UPDATE_CACHE(re, gb); +- buf = GET_CACHE(re, gb); +- +- log = av_log2(buf); +- +- av_assert2(k <= 31); +- +- if (log - k >= 32 - MIN_CACHE_BITS + (MIN_CACHE_BITS == 32) && +- 32 - log < limit) { +- buf >>= log - k; +- buf += (30U - log) << k; +- LAST_SKIP_BITS(re, gb, 32 + k - log); +- CLOSE_READER(re, gb); +- +- return buf; +- } else { +- int i; +- for (i = 0; i + MIN_CACHE_BITS <= limit && SHOW_UBITS(re, gb, MIN_CACHE_BITS) == 0; i += MIN_CACHE_BITS) { +- if (gb->size_in_bits <= re_index) { +- CLOSE_READER(re, gb); +- return -1; +- } +- LAST_SKIP_BITS(re, gb, MIN_CACHE_BITS); +- UPDATE_CACHE(re, gb); +- } +- for (; i < limit && SHOW_UBITS(re, gb, 1) == 0; i++) { +- SKIP_BITS(re, gb, 1); +- } +- LAST_SKIP_BITS(re, gb, 1); +- UPDATE_CACHE(re, gb); +- +- if (i < limit - 1) { +- if (k) { +- if (k > MIN_CACHE_BITS - 1) { +- buf = SHOW_UBITS(re, gb, 16) << (k-16); +- LAST_SKIP_BITS(re, gb, 16); +- UPDATE_CACHE(re, gb); +- buf |= SHOW_UBITS(re, gb, k-16); +- LAST_SKIP_BITS(re, gb, k-16); +- } else { +- buf = SHOW_UBITS(re, gb, k); +- LAST_SKIP_BITS(re, gb, k); +- } +- } else { +- buf = 0; +- } +- +- buf += ((SUINT)i << k); +- } else if (i == limit - 1) { +- buf = SHOW_UBITS(re, gb, esc_len); +- LAST_SKIP_BITS(re, gb, esc_len); +- +- buf ++; +- } else { +- buf = -1; +- } +- CLOSE_READER(re, gb); +- return buf; +- } +-#endif +-} +- +-/** +- * read signed golomb rice code (ffv1). +- */ +-static inline int get_sr_golomb(GetBitContext *gb, int k, int limit, +- int esc_len) +-{ +- unsigned v = get_ur_golomb(gb, k, limit, esc_len); +- return (v >> 1) ^ -(v & 1); +-} +- +-/** +- * read signed golomb rice code (flac). +- */ +-static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, +- int esc_len) +-{ +- unsigned v = get_ur_golomb_jpegls(gb, k, limit, esc_len); +- return (v >> 1) ^ -(v & 1); +-} +- +-/** +- * read unsigned golomb rice code (shorten). +- */ +-static inline unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k) +-{ +- return get_ur_golomb_jpegls(gb, k, INT_MAX, 0); +-} +- +-/** +- * read signed golomb rice code (shorten). +- */ +-static inline int get_sr_golomb_shorten(GetBitContext *gb, int k) +-{ +- int uvar = get_ur_golomb_jpegls(gb, k + 1, INT_MAX, 0); +- return (uvar >> 1) ^ -(uvar & 1); +-} +- + #ifdef TRACE + + static inline int get_ue(GetBitContext *s, const char *file, const char *func, +@@ -614,134 +475,4 @@ static inline int get_te(GetBitContext *s, int r, char *file, const char *func, + + #endif /* TRACE */ + +-/** +- * write unsigned exp golomb code. 2^16 - 2 at most +- */ +-static inline void set_ue_golomb(PutBitContext *pb, int i) +-{ +- av_assert2(i >= 0); +- av_assert2(i <= 0xFFFE); +- +- if (i < 256) +- put_bits(pb, ff_ue_golomb_len[i], i + 1); +- else { +- int e = av_log2(i + 1); +- put_bits(pb, 2 * e + 1, i + 1); +- } +-} +- +-/** +- * write unsigned exp golomb code. 2^32-2 at most. +- */ +-static inline void set_ue_golomb_long(PutBitContext *pb, uint32_t i) +-{ +- av_assert2(i <= (UINT32_MAX - 1)); +- +- if (i < 256) +- put_bits(pb, ff_ue_golomb_len[i], i + 1); +- else { +- int e = av_log2(i + 1); +- put_bits64(pb, 2 * e + 1, i + 1); +- } +-} +- +-/** +- * write truncated unsigned exp golomb code. +- */ +-static inline void set_te_golomb(PutBitContext *pb, int i, int range) +-{ +- av_assert2(range >= 1); +- av_assert2(i <= range); +- +- if (range == 2) +- put_bits(pb, 1, i ^ 1); +- else +- set_ue_golomb(pb, i); +-} +- +-/** +- * write signed exp golomb code. 16 bits at most. +- */ +-static inline void set_se_golomb(PutBitContext *pb, int i) +-{ +- i = 2 * i - 1; +- if (i < 0) +- i ^= -1; //FIXME check if gcc does the right thing +- set_ue_golomb(pb, i); +-} +- +-/** +- * write unsigned golomb rice code (ffv1). +- */ +-static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit, +- int esc_len) +-{ +- int e; +- +- av_assert2(i >= 0); +- +- e = i >> k; +- if (e < limit) +- put_bits(pb, e + k + 1, (1 << k) + av_mod_uintp2(i, k)); +- else +- put_bits(pb, limit + esc_len, i - limit + 1); +-} +- +-/** +- * write unsigned golomb rice code (jpegls). +- */ +-static inline void set_ur_golomb_jpegls(PutBitContext *pb, int i, int k, +- int limit, int esc_len) +-{ +- int e; +- +- av_assert2(i >= 0); +- +- e = (i >> k) + 1; +- if (e < limit) { +- while (e > 31) { +- put_bits(pb, 31, 0); +- e -= 31; +- } +- put_bits(pb, e, 1); +- if (k) +- put_sbits(pb, k, i); +- } else { +- while (limit > 31) { +- put_bits(pb, 31, 0); +- limit -= 31; +- } +- put_bits(pb, limit, 1); +- put_bits(pb, esc_len, i - 1); +- } +-} +- +-/** +- * write signed golomb rice code (ffv1). +- */ +-static inline void set_sr_golomb(PutBitContext *pb, int i, int k, int limit, +- int esc_len) +-{ +- int v; +- +- v = -2 * i - 1; +- v ^= (v >> 31); +- +- set_ur_golomb(pb, v, k, limit, esc_len); +-} +- +-/** +- * write signed golomb rice code (flac). +- */ +-static inline void set_sr_golomb_flac(PutBitContext *pb, int i, int k, +- int limit, int esc_len) +-{ +- int v; +- +- v = -2 * i - 1; +- v ^= (v >> 31); +- +- set_ur_golomb_jpegls(pb, v, k, limit, esc_len); +-} +- + #endif /* AVCODEC_GOLOMB_H */ +-- +2.32.0 +