I got a unity project which has to run on Android and Windows. To be able to decode raw H264 frames, I am using a ffmpeg wrapper, It works great on Windows but on Android I get a segmentation fault on av_log_default_callback, called by avcodec_decode_video2.
here is the backtrace :
05-26 10:47:45.224 24270 24286 F libc : Fatal signal 11 (SIGSEGV), code
1, fault addr 0x0 in tid 24286 (UnityMain)
05-26 10:47:45.224 463 463 W : debuggerd: handling request:
pid=24270 uid=10152 gid=10152 tid=24286
05-26 10:47:45.332 24535 24535 F DEBUG : *** *** *** *** *** *** *** ***
*** *** *** *** *** *** *** ***
05-26 10:47:45.332 24535 24535 F DEBUG : Revision: '0'
05-26 10:47:45.333 24535 24535 F DEBUG : ABI: 'arm'
05-26 10:47:45.333 24535 24535 F DEBUG : pid: 24270, tid: 24286, name:
UnityMain >>> com.my.app <<<
05-26 10:47:45.333 24535 24535 F DEBUG : signal 11 (SIGSEGV), code 1
(SEGV_MAPERR), fault addr 0x0
05-26 10:47:45.333 24535 24535 F DEBUG : r0 cf444220 r1 00000000 r2
00010000 r3 00000000
05-26 10:47:45.333 24535 24535 F DEBUG : r4 e9254b1c r5 00000010 r6
e9254b14 r7 e9255c90
05-26 10:47:45.333 24535 24535 F DEBUG : r8 c860f670 r9 cf444220 sl
e925531c fp e9254f1c
05-26 10:47:45.333 24535 24535 F DEBUG : ip 000003f0 sp e9254ac0 lr
cffa5518 pc 00000000 cpsr a8010010
05-26 10:47:45.339 24535 24535 F DEBUG :
05-26 10:47:45.339 24535 24535 F DEBUG : backtrace:
05-26 10:47:45.339 24535 24535 F DEBUG : #00 pc 00000000 <unknown>
05-26 10:47:45.339 24535 24535 F DEBUG : #01 pc 00018514
/data/app/com.my.app/lib/arm/libavutil-55.so
05-26 10:47:45.339 24535 24535 F DEBUG : #02 pc 000189f4
/data/app/com.my.app/lib/arm/libavutil-55.so
(av_log_default_callback+168)
05-26 10:47:45.339 24535 24535 F DEBUG : #03 pc 00018d38
/data/app/com.my.app/lib/arm/libavutil-55.so (av_log+80)
05-26 10:47:45.339 24535 24535 F DEBUG : #04 pc 001bf538
/data/app/com.my.app/lib/arm/libavcodec-57.so
05-26 10:47:45.339 24535 24535 F DEBUG : #05 pc 001c4eac
/data/app/com.my.app/lib/arm/libavcodec-57.so
05-26 10:47:45.339 24535 24535 F DEBUG : #06 pc 0038cce0
/data/app/com.my.app/lib/arm/libavcodec-57.so
(avcodec_decode_video2+380)
05-26 10:47:45.339 24535 24535 F DEBUG : #07 pc 00003490
<anonymous:cb624000>
I had to replace pointers by refs in the prototypes of the imported ffmpeg functions, to fix a Marshal error saying structs are not blittable and that I should use refs instead :
avcodec_decode_video2(AVCodecContext *ctx, AVFrame *frame, int *gotPicture,......);
became :
avcodec_decode_video2(ref AVCodecContext ctx, ref AVFrame frame, ref int gotPicture,.......);
everything works fine on Windows, using refs instead of pointer had no incidence and functions are now correctly imported on Android.
If anyone has infos that could be helpful to my research or know someone who had this bug, please share thank you !