Re: [FFmpeg-devel] [PATCH] Fix broken build on Android due to broken asm-generic/termbits.h include

2023-02-27 Thread zhilizhao(赵志立)


> On Feb 23, 2023, at 23:01, Hendrik Leppkes  wrote:
> 
> On Thu, Feb 23, 2023 at 3:37 PM copypaste  wrote:
>> It gets included because this platform does indeed have Video4Linux so some 
>> of the aarch64 stuff is relevant. Furthermore I think that the HEVC stuff 
>> includes it.
>> 
> 
> If its relevant for V4L or other hardware integration is fine and all
> ... but the real question is, how does it end up in aaccoder.c and
> other files entirely unrelated to video or hardware? And can we just
> get it out of those?

I know this issue exists for a long time. But I can’t reproduce it
these days.

https://github.com/android/ndk/issues/630
https://trac.ffmpeg.org/ticket/7130

The ‘B0’ macro comes from , which is defined by
asm-generic/termbits.h.  is included by libavutil/timer.h.
Thanks to the cleanup work done by Andreas Rheinhardt, the conflicts
has been reduced a lot, I think that’s why I didn’t get build errors.

Google suggests FFmpeg to fix the code problem, while NDK has
break more than one projects, see

https://github.com/jupyter-xeus/cpp-terminal/issues/35 

You can reproduce the build error with:

$ cat foo.c 
#include 

int main()
{
int B0 = 123;
}

$ make foo
cc foo.c   -o foo
foo.c:5:9: error: expected identifier or '('
int B0 = 123;
^
/data/data/com.termux/files/usr/include/asm-generic/termbits.h:118:12: note: 
expanded from macro 'B0'
#define B0 000
   ^
1 error generated.
make: *** [: foo] Error 1

> 
> - Hendrik
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] Fix broken build on Android due to broken asm-generic/termbits.h include

2023-02-24 Thread copypaste
  Here's my attempt to do just that. :-)  

 
Compiled fine with:
 

 
configuration: --prefix=/data/data/com.termux/files/usr/local 
--enable-indev=alsa --enable-indev=xcbgrab --enable-libfreetype 
--enable-libfontconfig --cc=clang --cxx=clang++ --disable-libxcb-shm 
--enable-vulkan --enable-opencl --enable-opengl --enable-libass 
--enable-libopus --enable-libfribidi --enable-librsvg --disable-stripping 
--enable-logging --enable-debug --logfile=/dev/tty --enable-nonfree 
--enable-jni --enable-gpl --enable-version3 --host-os=android 
--target-os=android --enable-mediacodec
 From 44d7cfe5d10b367b289549d90fabb3b985acb128 Mon Sep 17 00:00:00 2001
From: Fredrick Brennan 
Date: Fri, 24 Feb 2023 09:51:16 -0500
Subject: [PATCH] Prevent collisions between Android's asm-generic/termbits.h
 and ffmpeg

---
 libavcodec/aaccoder.c |  5 +
 libavcodec/faandct.c  | 15 +++
 libavcodec/hevcdec.h  |  9 +
 libavcodec/opus_pvq.h |  4 
 4 files changed, 33 insertions(+)

diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index 6291c16123..de51fa80fb 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -52,6 +52,11 @@
 
 #include "libavcodec/aaccoder_twoloop.h"
 
+#ifdef __ANDROID__
+#undef B0
+#undef B1
+#endif
+
 /* Parameter of f(x) = a*(lambda/100), defines the maximum fourier spread
  * beyond which no PNS is used (since the SFBs contain tone rather than noise) */
 #define NOISE_SPREAD_THRESHOLD 0.9f
diff --git a/libavcodec/faandct.c b/libavcodec/faandct.c
index 38c392bbae..923fa9beda 100644
--- a/libavcodec/faandct.c
+++ b/libavcodec/faandct.c
@@ -37,6 +37,21 @@ for this approach). Unfortunately, long double is not always available correctly
 e.g ppc has issues.
 TODO: add L suffixes when ppc and toolchains sort out their stuff.
 */
+#ifdef __ANDROID__
+#undef B0
+#undef B1
+#undef B2
+#undef B3
+#undef B4
+#undef B5
+#undef B6
+#undef B7
+#undef A1
+#undef A2
+#undef A3
+#undef A4
+#undef A5
+#endif
 #define B0 1.
 #define B1 0.720959822006947913789091890943021267 // (cos(pi*1/16)sqrt(2))^-1
 #define B2 0.765366864730179543456919968060797734 // (cos(pi*2/16)sqrt(2))^-1
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index 9d3f4adbb3..4b500350c0 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -57,6 +57,15 @@
 #define L0 0
 #define L1 1
 
+#ifdef __ANDROID__
+#undef A0
+#undef A1
+#undef A2
+#undef B0
+#undef B1
+#undef B2
+#endif
+
 #define EPEL_EXTRA_BEFORE 1
 #define EPEL_EXTRA_AFTER  2
 #define EPEL_EXTRA3
diff --git a/libavcodec/opus_pvq.h b/libavcodec/opus_pvq.h
index b71bc49034..91c59f2812 100644
--- a/libavcodec/opus_pvq.h
+++ b/libavcodec/opus_pvq.h
@@ -27,6 +27,10 @@
 
 #include "opus_celt.h"
 
+#ifdef __ANDROID__
+#undef B0
+#endif
+
 #define QUANT_FN(name) uint32_t (name)(struct CeltPVQ *pvq, CeltFrame *f,\
OpusRangeCoder *rc, const int band, float *X, \
float *Y, int N, int b, uint32_t blocks,  \
-- 
2.39.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] Fix broken build on Android due to broken asm-generic/termbits.h include

2023-02-23 Thread Hendrik Leppkes
On Thu, Feb 23, 2023 at 3:37 PM copypaste  wrote:
> It gets included because this platform does indeed have Video4Linux so some 
> of the aarch64 stuff is relevant. Furthermore I think that the HEVC stuff 
> includes it.
>

If its relevant for V4L or other hardware integration is fine and all
... but the real question is, how does it end up in aaccoder.c and
other files entirely unrelated to video or hardware? And can we just
get it out of those?

- Hendrik
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] Fix broken build on Android due to broken asm-generic/termbits.h include

2023-02-23 Thread copypaste
  Sorry Anton, I stupidly misread your message. You are telling me not to start 
my identifiers with underscores not talking about Android. Well, I can 
certainly change it but just making them lowercase will not fix the issue 
because those collide with ffmpeg's variables.  

 
Perhaps what I should do is more of the #undef thing I did in file   
libavcodec/hevcdec.h.
 
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] Fix broken build on Android due to broken asm-generic/termbits.h include

2023-02-23 Thread copypaste
 
 
 
It gets included because this platform does indeed have Video4Linux so some of 
the aarch64 stuff is relevant. Furthermore I think that the HEVC stuff includes 
it.
 

 
I have attached the file, whether or not it is not allowed seems immaterial 
because it is done by Android whether we like it or not.
 

 
 
 
 
 
>  
> On Feb 23, 2023 at 8:47 AM, Anton Khirnovwrote:
>  
>  
>  Quoting copypaste (2023-02-22 10:12:08) 
> >  Applied to libavcodec/aaccoder.c: 
> Why is that file even being included? 
>/
 
 ***
 ***   This header was automatically generated from a Linux kernel header
 ***   of the same name, to make information necessary for userspace to
 ***   call into the kernel available to libc.  It contains only constants,
 ***   structures, and macros generated from the original header, and thus,
 ***   contains no copyrightable information.
 ***
 ***   To edit the content of this header, modify the corresponding
 ***   source file (e.g. under external/kernel-headers/original/) then
 ***   run bionic/libc/kernel/tools/update_all.py
 ***
 ***   Any manual change here will be lost the next time this script will
 ***   be run. You've been warned!
 ***
 
 /
#ifndef __ASM_GENERIC_TERMBITS_H
#define __ASM_GENERIC_TERMBITS_H
#include 
typedef unsigned char cc_t;
typedef unsigned int speed_t;
typedef unsigned int tcflag_t;
#define NCCS 19
struct termios {
  tcflag_t c_iflag;
  tcflag_t c_oflag;
  tcflag_t c_cflag;
  tcflag_t c_lflag;
  cc_t c_line;
  cc_t c_cc[NCCS];
};
struct termios2 {
  tcflag_t c_iflag;
  tcflag_t c_oflag;
  tcflag_t c_cflag;
  tcflag_t c_lflag;
  cc_t c_line;
  cc_t c_cc[NCCS];
  speed_t c_ispeed;
  speed_t c_ospeed;
};
struct ktermios {
  tcflag_t c_iflag;
  tcflag_t c_oflag;
  tcflag_t c_cflag;
  tcflag_t c_lflag;
  cc_t c_line;
  cc_t c_cc[NCCS];
  speed_t c_ispeed;
  speed_t c_ospeed;
};
#define VINTR 0
#define VQUIT 1
#define VERASE 2
#define VKILL 3
#define VEOF 4
#define VTIME 5
#define VMIN 6
#define VSWTC 7
#define VSTART 8
#define VSTOP 9
#define VSUSP 10
#define VEOL 11
#define VREPRINT 12
#define VDISCARD 13
#define VWERASE 14
#define VLNEXT 15
#define VEOL2 16
#define IGNBRK 001
#define BRKINT 002
#define IGNPAR 004
#define PARMRK 010
#define INPCK 020
#define ISTRIP 040
#define INLCR 100
#define IGNCR 200
#define ICRNL 400
#define IUCLC 0001000
#define IXON 0002000
#define IXANY 0004000
#define IXOFF 001
#define IMAXBEL 002
#define IUTF8 004
#define OPOST 001
#define OLCUC 002
#define ONLCR 004
#define OCRNL 010
#define ONOCR 020
#define ONLRET 040
#define OFILL 100
#define OFDEL 200
#define NLDLY 400
#define NL0 000
#define NL1 400
#define CRDLY 0003000
#define CR0 000
#define CR1 0001000
#define CR2 0002000
#define CR3 0003000
#define TABDLY 0014000
#define TAB0 000
#define TAB1 0004000
#define TAB2 001
#define TAB3 0014000
#define XTABS 0014000
#define BSDLY 002
#define BS0 000
#define BS1 002
#define VTDLY 004
#define VT0 000
#define VT1 004
#define FFDLY 010
#define FF0 000
#define FF1 010
#define CBAUD 0010017
#define B0 000
#define B50 001
#define B75 002
#define B110 003
#define B134 004
#define B150 005
#define B200 006
#define B300 007
#define B600 010
#define B1200 011
#define B1800 012
#define B2400 013
#define B4800 014
#define B9600 015
#define B19200 016
#define B38400 017
#define EXTA B19200
#define EXTB B38400
#define CSIZE 060
#define CS5 000
#define CS6 020
#define CS7 040
#define CS8 060
#define CSTOPB 100
#define CREAD 200
#define PARENB 400
#define PARODD 0001000
#define HUPCL 0002000
#define CLOCAL 0004000
#define CBAUDEX 001
#define BOTHER 001
#define B57600 0010001
#define B115200 0010002
#define B230400 0010003
#define B460800 0010004
#define B50 0010005
#define B576000 0010006
#define B921600 0010007
#define B100 0010010
#define B1152000 0010011
#define B150 0010012
#define B200 0010013
#define B250 0010014
#define B300 0010015
#define B350 0010016
#define B400 0010017
#define CIBAUD 00200360
#define CMSPAR 0100
#define CRTSCTS 0200
#define IBSHIFT 16
#define ISIG 001
#define ICANON 002
#define XCASE 004
#define ECHO 010
#define ECHOE 020
#define ECHOK 040
#define ECHONL 100
#define NOFLSH 200
#define TOSTOP 400
#define ECHOCTL 0001000
#define ECHOPRT 0002000
#define ECHOKE 0004000
#define FLUSHO 001
#define PENDIN 004
#define IEXTEN 010
#define EXTPROC 020
#define TCOOFF 0
#define TCOON 1

Re: [FFmpeg-devel] [PATCH] Fix broken build on Android due to broken asm-generic/termbits.h include

2023-02-23 Thread Anton Khirnov
Quoting copypaste (2023-02-22 10:12:08)
> Applied to libavcodec/aaccoder.c:
> :%s/\([*]\)\?\([ \t]\{-}\)\?\(\<[BD-Z]\([0-9]*\)\)\>/\1\2_\3/g
> 
> This stops B0 and B1 from colliding with a define in
> /usr/include/asm-generic/termbits.h:

Why is that file even being included?

Also
> All identifiers that begin with an underscore and either an uppercase
> letter or another underscore are always reserved for any use.

-- 
Anton Khirnov
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] Fix broken build on Android due to broken asm-generic/termbits.h include

2023-02-22 Thread copypaste
 
 
 
Best,
 
Fred Brennan (copypaste.wtf)
 

 

 

 
 
 From e9a889bfbf38bda7855792edd8248f4f4a56af7e Mon Sep 17 00:00:00 2001
From: Fredrick Brennan 
Date: Tue, 21 Feb 2023 12:58:38 -0500
Subject: [PATCH 1/2] Fix build on Android due to termbits.h collision!

Applied to libavcodec/aaccoder.c:
:%s/\([*]\)\?\([ \t]\{-}\)\?\(\<[BD-Z]\([0-9]*\)\)\>/\1\2_\3/g

This stops B0 and B1 from colliding with a define in
/usr/include/asm-generic/termbits.h:

```c
```

Because of other defines in the file I used a more inclusive regex as
there's a warning at top that it's autogenerated and may be expanded.
---
 libavcodec/aaccoder.c | 62 +--
 1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index 6291c16123..35791c3040 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -83,8 +83,8 @@ static av_always_inline float quantize_and_encode_band_cost_template(
 const float ROUNDING)
 {
 const int q_idx = POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512;
-const float Q   = ff_aac_pow2sf_tab [q_idx];
-const float Q34 = ff_aac_pow34sf_tab[q_idx];
+const float _Q   = ff_aac_pow2sf_tab [q_idx];
+const float _Q34 = ff_aac_pow34sf_tab[q_idx];
 const float IQ  = ff_aac_pow2sf_tab [POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
 const float CLIPPED_ESCAPE = 165140.0f*IQ;
 float cost = 0;
@@ -111,7 +111,7 @@ static av_always_inline float quantize_and_encode_band_cost_template(
 s->abs_pow34(s->scoefs, in, size);
 scaled = s->scoefs;
 }
-s->quant_bands(s->qcoefs, in, scaled, size, !BT_UNSIGNED, aac_cb_maxval[cb], Q34, ROUNDING);
+s->quant_bands(s->qcoefs, in, scaled, size, !BT_UNSIGNED, aac_cb_maxval[cb], _Q34, ROUNDING);
 if (BT_UNSIGNED) {
 off = 0;
 } else {
@@ -138,7 +138,7 @@ static av_always_inline float quantize_and_encode_band_cost_template(
 quantized = CLIPPED_ESCAPE;
 curbits += 21;
 } else {
-int c = av_clip_uintp2(quant(t, Q, ROUNDING), 13);
+int c = av_clip_uintp2(quant(t, _Q, ROUNDING), 13);
 quantized = c*cbrtf(c)*IQ;
 curbits += av_log2(c)*2 - 4 + 1;
 }
@@ -175,7 +175,7 @@ static av_always_inline float quantize_and_encode_band_cost_template(
 if (BT_ESC) {
 for (int j = 0; j < 2; j++) {
 if (ff_aac_codebook_vectors[cb-1][curidx*2+j] == 64.0f) {
-int coef = av_clip_uintp2(quant(fabsf(in[i+j]), Q, ROUNDING), 13);
+int coef = av_clip_uintp2(quant(fabsf(in[i+j]), _Q, ROUNDING), 13);
 int len = av_log2(coef);
 
 put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);
@@ -979,9 +979,9 @@ static void search_for_ms(AACEncContext *s, ChannelElement *cpe)
 {
 int start = 0, i, w, w2, g, sid_sf_boost, prev_mid, prev_side;
 uint8_t nextband0[128], nextband1[128];
-float *M   = s->scoefs + 128*0, *S   = s->scoefs + 128*1;
-float *L34 = s->scoefs + 128*2, *R34 = s->scoefs + 128*3;
-float *M34 = s->scoefs + 128*4, *S34 = s->scoefs + 128*5;
+float *_M   = s->scoefs + 128*0, *_S   = s->scoefs + 128*1;
+float *_L34 = s->scoefs + 128*2, *_R34 = s->scoefs + 128*3;
+float *_M34 = s->scoefs + 128*4, *_S34 = s->scoefs + 128*5;
 const float lambda = s->lambda;
 const float mslambda = FFMIN(1.0f, lambda / 120.f);
 SingleChannelElement *sce0 = >ch[0];
@@ -1007,22 +1007,22 @@ static void search_for_ms(AACEncContext *s, ChannelElement *cpe)
 /* Must compute mid/side SF and book for the whole window group */
 for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) {
 for (i = 0; i < sce0->ics.swb_sizes[g]; i++) {
-M[i] = (sce0->coeffs[start+(w+w2)*128+i]
+_M[i] = (sce0->coeffs[start+(w+w2)*128+i]
   + sce1->coeffs[start+(w+w2)*128+i]) * 0.5;
-S[i] =  M[i]
+_S[i] =  _M[i]
   - sce1->coeffs[start+(w+w2)*128+i];
 }
-s->abs_pow34(M34, M, sce0->ics.swb_sizes[g]);
-s->abs_pow34(S34, S, sce0->ics.swb_sizes[g]);
+s->abs_pow34(_M34, _M, sce0->ics.swb_sizes[g]);
+s->abs_pow34(_S34, _S, sce0->ics.swb_sizes[g]);
 for (i = 0; i < sce0->ics.swb_sizes[g]; i++ ) {
-Mmax = FFMAX(Mmax, M34[i]);
-Smax = FFMAX(Smax, S34[i]);
+Mmax = FFMAX(Mmax, _M34[i]);
+Smax = FFMAX(Smax, _S34[i]);
 }
 }
 
 for (sid_sf_boost =