GloDroid / glodroid_manifest

Android port that aims to bring both user- and developer-friendly experience in using AOSP with a set of single-board computers (SBC), phones and other devices.
471 stars 67 forks source link

Hardware information apps crash on Pi 4 #160

Closed KonstaT closed 2 years ago

KonstaT commented 2 years ago

@rsglobal Hi Roman. Great job on the GloDroid v0.7.0 release!

I wanted to report a regression on Mesa related to switching to the Meson build system. Not sure if you want this here or Mesa issue tracker.

I can reproduce this on GloDroid v0.7.0 and my LineageOS builds as well. Launching any(?) system/hardware information application will shortly crash with following log:

10-08 11:30:04.479  3072  3072 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
10-08 11:30:04.479  3072  3072 F DEBUG   : Build fingerprint: 'RaspberryPI/rpi4/rpi4:12/SP1A.210812.016/eng.roman.20211005.170921:userdebug/test-keys'
10-08 11:30:04.479  3072  3072 F DEBUG   : Revision: '1.0'
10-08 11:30:04.480  3072  3072 F DEBUG   : ABI: 'arm64'
10-08 11:30:04.480  3072  3072 F DEBUG   : Timestamp: 2021-10-08 11:30:03.001342134+0000
10-08 11:30:04.480  3072  3072 F DEBUG   : Process uptime: 5s
10-08 11:30:04.481  3072  3072 F DEBUG   : Cmdline: com.finalwire.aida64
10-08 11:30:04.481  3072  3072 F DEBUG   : pid: 2915, tid: 3043, name: GLThread 83  >>> com.finalwire.aida64 <<<
10-08 11:30:04.481  3072  3072 F DEBUG   : uid: 10075
10-08 11:30:04.481  3072  3072 F DEBUG   : tagged_addr_ctrl: 0000000000000001
10-08 11:30:04.482  3072  3072 F DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
10-08 11:30:04.482  3072  3072 F DEBUG   : Abort message: 'Scudo ERROR: invalid chunk state when deallocating address 0x200007cf39e3110
10-08 11:30:04.482  3072  3072 F DEBUG   : '
10-08 11:30:04.482  3072  3072 F DEBUG   :     x0  0000000000000000  x1  0000000000000be3  x2  0000000000000006  x3  0000007c058539e0
10-08 11:30:04.483  3072  3072 F DEBUG   :     x4  0000000000808080  x5  0000000000808080  x6  0000000000808080  x7  8080800000000000
10-08 11:30:04.483  3072  3072 F DEBUG   :     x8  00000000000000f0  x9  0000007f6eb060b0  x10 ffffff00fffffbdf  x11 0000000000000001
10-08 11:30:04.483  3072  3072 F DEBUG   :     x12 0101010101010101  x13 0000000000000030  x14 0000000000000000  x15 0000000000000070
10-08 11:30:04.484  3072  3072 F DEBUG   :     x16 0000007f6eba6050  x17 0000007f6eb82700  x18 0000007c047e4000  x19 00000000000000ac
10-08 11:30:04.484  3072  3072 F DEBUG   :     x20 0000000000000b63  x21 00000000000000b2  x22 0000000000000be3  x23 00000000ffffffff
10-08 11:30:04.484  3072  3072 F DEBUG   :     x24 0000007c05853cb0  x25 0000007c05853cb0  x26 0000007c05853ff8  x27 000000000010a000
10-08 11:30:04.484  3072  3072 F DEBUG   :     x28 0000000000108000  x29 0000007c05853a60
10-08 11:30:04.485  3072  3072 F DEBUG   :     lr  0000007f6eb33efc  sp  0000007c058539c0  pc  0000007f6eb33f2c  pst 0000000000000000
10-08 11:30:04.485  3072  3072 F DEBUG   : backtrace:
10-08 11:30:04.485  3072  3072 F DEBUG   :       #00 pc 000000000004ff2c  /apex/com.android.runtime/lib64/bionic/libc.so (abort+180) (BuildId: ac3d0baaacdc7c6cdebcc4f2fe5705dd)
10-08 11:30:04.486  3072  3072 F DEBUG   :       #01 pc 0000000000040430  /apex/com.android.runtime/lib64/bionic/libc.so (scudo::die()+8) (BuildId: ac3d0baaacdc7c6cdebcc4f2fe5705dd)
10-08 11:30:04.486  3072  3072 F DEBUG   :       #02 pc 0000000000040c08  /apex/com.android.runtime/lib64/bionic/libc.so (scudo::ScopedErrorReport::~ScopedErrorReport()+32) (BuildId: ac3d0baaacdc7c6cdebcc4f2fe57
05dd)
10-08 11:30:04.486  3072  3072 F DEBUG   :       #03 pc 0000000000040e44  /apex/com.android.runtime/lib64/bionic/libc.so (scudo::reportInvalidChunkState(scudo::AllocatorAction, void*)+76) (BuildId: ac3d0baaacdc7
c6cdebcc4f2fe5705dd)
10-08 11:30:04.487  3072  3072 F DEBUG   :       #04 pc 0000000000042464  /apex/com.android.runtime/lib64/bionic/libc.so (scudo::Allocator<scudo::AndroidConfig, &(scudo_malloc_postinit)>::deallocate(void*, scudo
::Chunk::Origin, unsigned long, unsigned long)+308) (BuildId: ac3d0baaacdc7c6cdebcc4f2fe5705dd)
10-08 11:30:04.487  3072  3072 F DEBUG   :       #05 pc 000000000001844c  /vendor/lib64/egl/libEGL_mesa.so (BuildId: d9ef3557a41fde917808c1f16247ef3d)
10-08 11:30:04.487  3072  3072 F DEBUG   :       #06 pc 000000000001245c  /vendor/lib64/egl/libEGL_mesa.so (eglReleaseThread+20) (BuildId: d9ef3557a41fde917808c1f16247ef3d)
10-08 11:30:04.487  3072  3072 F DEBUG   :       #07 pc 00000000000204ac  /system/lib64/libEGL.so (android::eglReleaseThreadImpl()+36) (BuildId: e162bdb7137f5a71946fd1b9cf5c1810)
10-08 11:30:04.488  3072  3072 F DEBUG   :       #08 pc 0000000000014080  /system/lib64/libEGL.so (android::egl_tls_t::destructTLSData(void*)+32) (BuildId: e162bdb7137f5a71946fd1b9cf5c1810)
10-08 11:30:04.488  3072  3072 F DEBUG   :       #09 pc 00000000000b3e24  /apex/com.android.runtime/lib64/bionic/libc.so (pthread_key_clean_all()+132) (BuildId: ac3d0baaacdc7c6cdebcc4f2fe5705dd)
10-08 11:30:04.488  3072  3072 F DEBUG   :       #10 pc 00000000000b35b0  /apex/com.android.runtime/lib64/bionic/libc.so (pthread_exit+72) (BuildId: ac3d0baaacdc7c6cdebcc4f2fe5705dd)
10-08 11:30:04.489  3072  3072 F DEBUG   :       #11 pc 00000000000b343c  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+268) (BuildId: ac3d0baaacdc7c6cdebcc4f2fe5705dd)
10-08 11:30:04.489  3072  3072 F DEBUG   :       #12 pc 00000000000517c8  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: ac3d0baaacdc7c6cdebcc4f2fe5705dd)

This can be reproduced with AIDA64 (https://www.apkmirror.com/apk/finalwire-ltd/aida64/) and Droid Hardware Info (https://www.apkmirror.com/apk/inkwired/droid-hardware-info/) at least.

I've found that this is clearly something related to the Mesa Meson build. This issue is not present on Mesa 21.1 that still uses Android.mk to build. I've ported the Meson build patches to Mesa 21.1 and I can reproduce this with Mesa 21.1 as well after building it with Meson. Also happens with both gbm and minigbm grallocs. Any idea what could be the problem?

And another somewhat related question. Have you looked into building the Broadcom Vulkan Mesa driver? Would it be only a matter of building it as Android HAL as on other platforms (e.g. https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/amd/vulkan/radv_android.c, https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/freedreno/vulkan/tu_android.c) or would this require something on gralloc/hwcomposer as well? All the Vulkan test apps I've found also crash this same way. android-rpi has Vulkan implemented and it's just a wrapper that opens the Mesa Vulkan lib as Android HAL (https://github.com/android-rpi/hardware_arpi/tree/arpi-12/graphics/vulkan).

rsglobal commented 2 years ago

@KonstaT .

Thank you for reporting this issue. I'm currently busy with my regular work, therefore I will take a look/answer for your queries later.

The crash you've provided is likely related to TLS, which we've enabled with meson.build. Please try to disable it and check if crash is gone.

To disable it remove this https://gitlab.freedesktop.org/mesa/mesa/-/blob/5728a74ad2bf1c368cbab84b447faf7057c15447/meson.build#L497 section.

KonstaT commented 2 years ago

Thank you. Disabling TLS does indeed fix this crash!

rsglobal commented 2 years ago

It looks like some bad resource handling in v3d .I faced similar issue with v3d but in different scenarios 6 month ago not related to TLS.

Could you open the issue in mesa3d?

KonstaT commented 2 years ago

https://gitlab.freedesktop.org/mesa/mesa/-/issues/5466

rsglobal commented 2 years ago

About vulkan, android hwmodule entry is missing for broadcom,panfrost in mesa3d. Mesa3d should have generic android layer for vulkan, but for some reason it doesn't. I have this on my list, but as low priority task.

No changes in hwc and gralloc is needed, but arpi wrapper should be able to work with your gralloc

KonstaT commented 2 years ago

@rsglobal Thanks for sharing your insight. Made it worth a while to look into this.

I managed to get vulkan running on Mesa 21.2.3 and gbm gralloc. Built vulkan.broadcom as Android HAL as on other platforms. v3dv turned out to be pretty close how it's implemented on freedreno. Also having android-rpi as reference certainly helped.

rsglobal commented 2 years ago

That's great news. Do you have any plans to contribute your effort into mesa3d?

KonstaT commented 2 years ago

Will be open sourcing it of course. I don't know how upstreaming it would go being pseudonymous and some of it being @peyo-hd's code.

Still couple of things to look into. Would it also work with the old minigbm gralloc (currently doesn't)? And is it leaking memory because it's not doing v3dv_FreeMemory() (e.g. https://gitlab.freedesktop.org/mesa/mesa/-/blob/21.2/src/freedreno/vulkan/tu_image.c#L747-750)?

Edit. Never mind, seem to be having some unrelated issue with minigbm and sorted the memory thing.

rsglobal commented 2 years ago

I don't know how upstreaming it would go being pseudonymous and some of it being @peyo-hd's code.

I would recommend you to see the whole video, it's quite interesting, nice and fun to watch. Or see starting from 20:50 for a few minutes. Greg explains there why anonymous contributions are not permitted. https://www.youtube.com/watch?v=LLBrBBImJt4&t=1240s

KonstaT commented 2 years ago

So, basically someone else could just sign-off on the patch and submit it for review.

I seem to be having few more issues with Mesa 21.2. minigbm gralloc (https://github.com/lineage-rpi/android_external_minigbm/tree/lineage-18.1) I have an option to use doesn't work (not that big of a deal as I could just drop it). Android's native screen recording crashes (this I would like to have as it's quick and easy to way to test video encoding).

Also seeing bunch of these in dmesg (usually around when something crashes):

[  227.829132] vc4-drm gpu: swiotlb buffer is full (sz: 3055616 bytes), total 32768 (slots), used 268 (slots)
[  227.853247] vc4-drm gpu: swiotlb buffer is full (sz: 3055616 bytes), total 32768 (slots), used 268 (slots)
[  227.882924] vc4-drm gpu: swiotlb buffer is full (sz: 3055616 bytes), total 32768 (slots), used 268 (slots)
[  227.872098] vc4-drm gpu: swiotlb buffer is full (sz: 3055616 bytes), total 32768 (slots), used 270 (slots)
[  227.893396] vc4-drm gpu: swiotlb buffer is full (sz: 3055616 bytes), total 32768 (slots), used 268 (slots)

I'm probably going to stick with Mesa 21.1 for some time (at least for the next release) as it doesn't have the above issues. Got the Vulkan built with the Android.mk used in 21.1 though it requires porting some other v3dv patches as well. It works with both gbm/minigbm grallocs.

rsglobal commented 2 years ago

Oh, generic DRI backend has been abandoned long time ago. We are using gbm_mesa backend. It's not something I see a long-term solution but at least it allows to make step towards codecs,cameras, more optimizations and compatibility fixes. https://github.com/GloDroid/glodroid_forks/tree/minigbm-v0.7.0

KonstaT commented 2 years ago

I have your 'egl: android: add gbm_gralloc and drm_gralloc support' patch (https://github.com/lineage-rpi/android_external_mesa3d/commit/28cb1fcea3ec7e057ca38e49fd6093f40a943af8) on Mesa 21.1/21.2 to use the gbm/minigbm grallocs (https://github.com/lineage-rpi/android_external_gbm_gralloc/tree/lineage-18.1, https://github.com/lineage-rpi/android_external_minigbm/tree/lineage-18.1).

I've also tested switching to the migbm you linked with https://github.com/GloDroid/glodroid_device/commit/12dd2cd734f679481c0e7a4902b7a72793f8fd4e. I don't have video dec/enc and camera working with that.

rsglobal commented 2 years ago

I've also tested switching to the migbm you linked with GloDroid/glodroid_device@12dd2cd. I don't have video dec/enc and camera working with that.

I'll look into this. Thanks.

KonstaT commented 2 years ago

Mesa 21.1 with Broadcom Vulkan support is now here: https://github.com/lineage-rpi/android_external_mesa3d/tree/lineage-18.1

I also attached a patch on top of current Mesa 21.2 for the Meson build if you want to test (main seems to have some conflicting changes and I don't have time for testing it right now): v3dv-add-android-support.zip

BoardConfig.mk (when built with Meson):

BOARD_MESA3D_VULKAN_DRIVERS := broadcom

device.mk:

PRODUCT_PACKAGES += \
    vulkan.broadcom

PRODUCT_COPY_FILES += \
    frameworks/native/data/etc/android.hardware.vulkan.level-1.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.level.xml \
    frameworks/native/data/etc/android.hardware.vulkan.version-1_0_3.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version.xml

system.prop:

ro.hardware.vulkan=broadcom

file_context:

/vendor/lib(64)?/hw/vulkan\.broadcom\.so u:object_r:same_process_hal_file:s0
KonstaT commented 2 years ago

Closing this as the original issue is now discussed on Mesa issue tracker.

rsglobal commented 2 years ago

I also attached a patch on top of current Mesa 21.2 for the Meson build if you want to test (main seems to have some conflicting changes and I don't have time for testing it right now):

Thanks. Don't you mind if I'll upstream it?

KonstaT commented 2 years ago

Not at all. Please go ahead if you've tested it working.

rsglobal commented 2 years ago

I have your 'egl: android: add gbm_gralloc and drm_gralloc support' patch (lineage-rpi/android_external_mesa3d@28cb1fc) on Mesa 21.1/21.2 to use the gbm/minigbm grallocs (https://github.com/lineage-rpi/android_external_gbm_gralloc/tree/lineage-18.1, https://github.com/lineage-rpi/android_external_minigbm/tree/lineage-18.1).

I've also tested switching to the migbm you linked with GloDroid/glodroid_device@12dd2cd. I don't have video dec/enc and camera working with that.

I've fixed some issues related to camera and screen record.

KonstaT commented 2 years ago

I've fixed some issues related to camera and screen record.

Yeah, thanks. I've already switched to minigbm and gralloc@4 on the latest LineageOS 18 & 19 builds. Part of the issues I was having was just me being stupid as usual. :P

Camera with the old HAL I was using is now dead on Android 12 because Google droppped support for HALv1 (https://android.googlesource.com/platform/frameworks/av/+/a976df84a463b83f5093ee34e00a726779f34308). IDK if LineageOS folks still need it for some devices and bring it back but it's not a long term solution anyway. I probably also need to start looking into libcamera.

And BTW saw your patch on v4l2_codec2 gerrit. You commented that you can't test it in real conditions. Am I missing something why this couldn't work on Pi 4? I checked with a Pi engineer and H.264 hw dec/enc works with KMS (though uses firmware for something that I don't know). So the stateful H.264 should be possible with v4l2_codec2 while stateless H.265 is not? https://github.com/raspberrypi/linux/issues/4651#issuecomment-950947950

Which leads to the whole KMS vs. FKMS situation on Pi. You probably have pretty good understanding what exactly is the problem that drm_hwcomposer doesn't work when FKMS is used? Is it because the drm devices KMS/FKMS create are different or does the firmware mess with the composition in some other way? Basically it's never worked on any Pi as long I've been around and I've just believed people who know better than me that it doesn't work.

rsglobal commented 2 years ago

And BTW saw your patch on v4l2_codec2 gerrit. You commented that you can't test it in real conditions. Am I missing something why this couldn't work on Pi 4?

I haven't tried it yet on rpi4. You've said it doesn't work, so I decided to wait until John and Neil succeed.

Which leads to the whole KMS vs. FKMS situation on Pi. You probably have pretty good understanding what exactly is the problem that drm_hwcomposer doesn't work when FKMS is used?

F means fake? Why do we need something fake? I guess I've never tried FKMS.

KonstaT commented 2 years ago

I haven't tried it yet on rpi4. You've said it doesn't work, so I decided to wait until John and Neil succeed.

Ok, I haven't gotten any further than last we discussed (E V4L2Device: No devices supporting H264 for type: 0). Just wondered if I missed something. I've seen John's status updates on Twitter but obviously haven't even gotten that far.

F means fake? Why do we need something fake? I guess I've never tried FKMS.

Fake or firmware depending on the source or who you ask. :) The whole situation is pretty undocumented and the feature set that they support is not the same. FKMS allows to configure the display with the firmware e.g. using hdmi_* properties in config.txt (which are ignored on KMS - only way to pass some display configuration to the kernel is via cmdline). FKMS is used by default on Raspberry Pi OS and I guess all the other "normal" Linux distros as well.

KonstaT commented 2 years ago

John succeeded (https://twitter.com/johnstultz_work/status/1456769717901750274). Issue he was having was with qcom specific modifier so don't know what's up with Pi 4.

rsglobal commented 2 years ago

That's great news. My Android build for rpi4 is suffering from some stable patch somewhere in between of v5.10.17-5.10.20 . System is completly hanging during bootanimation. Same is on v5.15. I will try to bisect it on Monday and hope updating the kernel will help to enable csi camera or codecs. BTW, have you experienced such hanging issue?

KonstaT commented 2 years ago

No, never come across such issue. Latest is 5.10.74 I've had running and with a quick look at least .0, .9, .16, .52, .63 before that. Only issue I have with 5.10 right now is that there is no HDMI audio (https://github.com/raspberrypi/linux/issues/4651 & https://github.com/raspberrypi/linux/issues/4654) so I'm stuck with 5.4 kernel on release builds for now.

Could be a firmware related issue as well. The firmware does strange things on Pi as I've come to notice. It's always best to keep the boot firmware inline with the kernel version (https://github.com/raspberrypi/firmware/commits/master/boot). For mainline kernel it's probably from https://github.com/raspberrypi/firmware/commits/next/boot

KonstaT commented 2 years ago

Made some progress with hw video dec/enc. Duh, no wonder it didn't find anything on Pi 4 (https://android.googlesource.com/platform/external/v4l2_codec2/+/refs/heads/master/common/V4L2Device.cpp#1989). :)

Running into memory allocation issues now. Added gralloc to support DRM_FORMAT_R8 which made the encoder come alive (still crashes for other reasons) and decoder just shows black screen.

11-06 19:37:35.137   290  1691 E ion     : ioctl c0044901 failed with code -1: Inappropriate ioctl for device
rsglobal commented 2 years ago

I believe ion error can be ignored. I saw a lot of them with sw codecs. It's likely a probing of API version. Here is a John's work: https://issuetracker.google.com/issues/202923667?pli=1#comment50

KonstaT commented 2 years ago

Thanks for the link. Have to read the whole discussion with better time. Looks like I'm only missing the kernel patch for what was needed (non-qcom specific stuff) and that looks like nothing I have on 5.4. Will check and test this with 5.10 next week as well.

rsglobal commented 2 years ago

Made some progress with hw video dec/enc. Duh, no wonder it didn't find anything on Pi 4

I've pushed the patch: https://android-review.googlesource.com/c/platform/external/v4l2_codec2/+/1882080

KonstaT commented 2 years ago

Looks good to me. Stateless HEVC is /dev/video19 but that's not in the scope with v4l2_codec2 now anyway.

Tested with 5.10 kernel with/without John's kernel patch. Probably doesn't even get that far to make any difference.

11-08 12:49:22.527   307  1753 I GenericSource: start
11-08 12:49:22.535   307  1758 D CCodec  : allocate(c2.v4l2.avc.decoder)
11-08 12:49:22.544   307  1758 I CCodec  : setting up 'default' as default (vendor) store
11-08 12:49:22.547   307  1758 I CCodec  : Created component [c2.v4l2.avc.decoder]
11-08 12:49:22.547   307  1758 W Codec2Client: query -- param skipped: index = 2684356613.
11-08 12:49:22.547   307  1758 D CCodecConfig: Query domain & kind[  139.148359] contiguous chunk is too small 393216/786432
 failed => BAD_INDEX
11-08 12:49:22.548   307  1758 D CCodecConfig: read media type: video/avc
11-08 12:49:22.548   307  1758 D CCodecConfig: read media type: video/avc
11-08 12:49:22.551   307  1758 D ReflectedParamUpdater: extent() != 1 for single value type: input.buffers.allocator-ids.values
11-08 12:49:22.552   307  1758 D ReflectedParamUpdater: extent() != 1 for single value type: output.buffers.allocator-ids.values
11-08 12:49:22.552   307  1758 D ReflectedParamUpdater: extent() != 1 for single value type: output.buffers.pool-ids.values
11-08 12:49:22.555   307  1758 D CCodecConfig: ignoring local param raw.size (0xd2001800) as it is already supported
11-08 12:49:22.555   307  1758 D CCodecConfig: ignoring local param default.color (0x5200180b) as it is already supported
11-08 12:49:22.556   307  1758 D ReflectedParamUpdater: ignored struct field raw.hdr-static-info.mastering
11-08 12:49:22.558   307  1758 I CCodecConfig: query failed after returning 9 values (BAD_INDEX)
11-08 12:49:22.559   307  1758 D CCodecConfig: c2 config diff is Dict {
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 coded.pl.level = 20491
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 coded.pl.profile = 20482
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 coded.vui.color.matrix = 0
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 coded.vui.color.primaries = 0
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 coded.vui.color.range = 2
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 coded.vui.color.transfer = 0
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 default.color.matrix = 0
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 default.color.primaries = 0
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 default.color.range = 0
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 default.color.transfer = 0
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 input.buffers.max-size.value = 786432
11-08 12:49:22.559   307  1758 D CCodecConfig:   string input.media-type.value = "video/avc"
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 output.delay.value = 16
11-08 12:49:22.559   307  1758 D CCodecConfig:   string output.media-type.value = "video/raw"
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 raw.color.matrix = 0
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 raw.color.primaries = 0
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 raw.color.range = 2
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 raw.color.transfer = 0
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::i32 raw.rotation.flip = 0
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::i32 raw.rotation.value = 0
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 raw.sar.height = 1
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 raw.sar.width = 1
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 raw.size.height = 240
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 raw.size.width = 320
11-08 12:49:22.559   307  1758 D CCodecConfig:   c2::u32 raw.surface-scaling.value = 1
11-08 12:49:22.559   307  1758 D CCodecConfig: }
11-08 12:49:22.565   307  1758 W ColorUtils: expected specified color aspects (2:0:0:0)
11-08 12:49:22.567   307  1756 D SurfaceUtils: disconnecting from surface 0xf15c1948, reason onConfigure
11-08 12:49:22.568   307  1757 D SurfaceUtils: connecting to surface 0xf15c1948, reason connectToSurface
11-08 12:49:22.572   307  1757 I MediaCodec: [c2.v4l2.avc.decoder] setting surface generation to 314369
11-08 12:49:22.572   307  1757 D SurfaceUtils: disconnecting from surface 0xf15c1948, reason connectToSurface(reconnect)
11-08 12:49:22.574   307  1757 D SurfaceUtils: connecting to surface 0xf15c1948, reason connectToSurface(reconnect)
11-08 12:49:22.575   307  1758 D CCodec  : [c2.v4l2.avc.decoder] buffers are bound to CCodec for this session
11-08 12:49:22.576   307  1758 D CCodecConfig: no c2 equivalents for durationUs
11-08 12:49:22.576   307  1758 D CCodecConfig: no c2 equivalents for frame-count
11-08 12:49:22.576   307  1758 D CCodecConfig: no c2 equivalents for track-id
11-08 12:49:22.576   307  1758 D CCodecConfig: no c2 equivalents for language
11-08 12:49:22.576   307  1758 D CCodecConfig: no c2 equivalents for display-width
11-08 12:49:22.576   307  1758 D CCodecConfig: no c2 equivalents for display-height
11-08 12:49:22.576   307  1758 D CCodecConfig: no c2 equivalents for color-standard
11-08 12:49:22.576   307  1758 D CCodecConfig: no c2 equivalents for csd-1
11-08 12:49:22.576   307  1758 D CCodecConfig: no c2 equivalents for native-window
11-08 12:49:22.577   307  1758 D CCodecConfig: no c2 equivalents for flags
11-08 12:49:22.578   307  1758 D CCodecConfig: c2 config diff is   c2::u32 coded.pl.level = 20493
11-08 12:49:22.578   307  1758 D CCodecConfig:   c2::u32 coded.pl.profile = 20481
11-08 12:49:22.578   307  1758 D CCodecConfig:   c2::u32 default.color.matrix = 1
11-08 12:49:22.578   307  1758 D CCodecConfig:   c2::u32 default.color.primaries = 1
11-08 12:49:22.578   307  1758 D CCodecConfig:   c2::u32 default.color.range = 2
11-08 12:49:22.578   307  1758 D CCodecConfig:   c2::u32 default.color.transfer = 3
11-08 12:49:22.578   307  1758 D CCodecConfig:   c2::u32 raw.size.height = 1080
11-08 12:49:22.578   307  1758 D CCodecConfig:   c2::u32 raw.size.width = 1920
11-08 12:49:22.578   307  1758 D CCodec  : client requested max input size 109947, which is smaller than what component recommended (786432); overriding with component recommendation.
11-08 12:49:22.578   307  1758 W CCodec  : This behavior is subject to change. It is recommended that app developers double check whether the requested max input size is in reasonable range.
11-08 12:49:22.578   307  1758 D CCodec  : setup formats input: AMessage(what = 0x00000000) = {
11-08 12:49:22.578   307  1758 D CCodec  :   int32_t height = 1080
11-08 12:49:22.578   307  1758 D CCodec  :   int32_t level = 8192
11-08 12:49:22.578   307  1758 D CCodec  :   int32_t max-input-size = 786432
11-08 12:49:22.578   307  1758 D CCodec  :   string mime = "video/avc"
11-08 12:49:22.578   307  1758 D CCodec  :   int32_t profile = 65536
11-08 12:49:22.578   307  1758 D CCodec  :   int32_t width = 1920
11-08 12:49:22.578   307  1758 D CCodec  :   Rect crop(0, 0, 1919, 1079)
11-08 12:49:22.578   307  1758 D CCodec  :   int64_t android._C2MemoryUsage = 4194304
11-08 12:49:22.578   307  1758 D CCodec  : }
11-08 12:49:22.579   307  1758 D CCodec  : setup formats output: AMessage(what = 0x00000000) = {
11-08 12:49:22.579   307  1758 D CCodec  :   int32_t android._video-scaling = 1
11-08 12:49:22.579   307  1758 D CCodec  :   int32_t rotation-degrees = 0
11-08 12:49:22.579   307  1758 D CCodec  :   int32_t color-standard = 1
11-08 12:49:22.579   307  1758 D CCodec  :   int32_t color-range = 2
11-08 12:49:22.579   307  1758 D CCodec  :   int32_t color-transfer = 3
11-08 12:49:22.579   307  1758 D CCodec  :   int32_t sar-height = 1
11-08 12:49:22.579   307  1758 D CCodec  :   int32_t sar-width = 1
11-08 12:49:22.579   307  1758 D CCodec  :   Rect crop(0, 0, 1919, 1079)
11-08 12:49:22.579   307  1758 D CCodec  :   int32_t width = 1920
11-08 12:49:22.579   307  1758 D CCodec  :   int32_t height = 1080
11-08 12:49:22.579   307  1758 D CCodec  :   string mime = "video/raw"
11-08 12:49:22.579   307  1758 D CCodec  :   int32_t android._dataspace = 260
11-08 12:49:22.579   307  1758 D CCodec  :   int32_t color-format = 2130708361
11-08 12:49:22.579   307  1758 D CCodec  : }
11-08 12:49:22.579   307  1758 I CCodecConfig: query failed after returning 9 values (BAD_INDEX)
11-08 12:49:22.579   307  1758 D CCodecConfig: c2 config diff is   c2::u32 raw.color.matrix = 1
11-08 12:49:22.579   307  1758 D CCodecConfig:   c2::u32 raw.color.primaries = 1
11-08 12:49:22.579   307  1758 D CCodecConfig:   c2::u32 raw.color.transfer = 3
11-08 12:49:22.580   307  1757 I MediaCodec: MediaCodec will operate in async mode
11-08 12:49:22.580   307  1756 D MediaCodec: keep callback message for reclaim
11-08 12:49:22.583   278  1759 D V4L2Device: (OUTPUT_MPLANE)Requesting 16 buffers.
11-08 12:49:22.588   278  1759 D V4L2Device: (OUTPUT_MPLANE)Queue 10: got 16 buffers.
11-08 12:49:22.598   307  1758 W Codec2Client: query -- param skipped: index = 1342179345.
11-08 12:49:22.598   307  1758 W Codec2Client: query -- param skipped: index = 2415921170.
11-08 12:49:22.598   307  1758 W Codec2Client: query -- param skipped: index = 1073743886.
11-08 12:49:22.598   307  1758 W Codec2Client: query -- param skipped: index = 1610614798.
11-08 12:49:22.599   307  1758 W Codec2Client: query -- param skipped: index = 2684356609.
11-08 12:49:22.600   307  1758 D CCodecBufferChannel: [c2.v4l2.avc.decoder#464] Created input block pool with allocatorID 16 => poolID 18 - OK (0)
11-08 12:49:22.600   312   645 D BufferPoolAccessor2.0: bufferpool2 0xb40000725b757848 : 0(0 size) total buffers - 0(0 size) used buffers - 50/54 (recycle/alloc) - 4/53 (fetch/transfer)
11-08 12:49:22.600   312   645 D BufferPoolAccessor2.0: Destruction - bufferpool2 0xb40000725b757848 cached: 0/0M, 0/0% in use; allocs: 54, 93% recycled; transfers: 53, 92% unfetched
11-08 12:49:22.671   307  1758 I VendorAllocatorLoader: Create(): Failed to load library: libv4l2_codec2_vendor_allocator.so
11-08 12:49:22.672   307  1758 I V4L2PluginStore: createAllocator(): Fallback to create C2AllocatorGralloc(id=21)
11-08 12:49:22.673   307  1758 I V4L2PluginStore: createAllocator(): Fallback to create C2AllocatorGralloc(id=20)
11-08 12:49:22.674   278   634 I VendorAllocatorLoader: Create(): Failed to load library: libv4l2_codec2_vendor_allocator.so
11-08 12:49:22.674   278   634 I V4L2PluginStore: createAllocator(): Fallback to create C2AllocatorGralloc(id=20)
11-08 12:49:22.677   307  1758 I CCodecBufferChannel: [c2.v4l2.avc.decoder#464] Created output block pool with allocatorID 20 => poolID 17 - OK
11-08 12:49:22.678   307  1758 D CCodecBufferChannel: [c2.v4l2.avc.decoder#464] Configured output block pool ids 17 => OK
11-08 12:49:22.678   307  1758 D Codec2-OutputBufferQueue: remote graphic buffer migration 0/0
11-08 12:49:22.679   307  1758 D Codec2Client: setOutputSurface -- failed to set consumer usage (6/BAD_INDEX)
11-08 12:49:22.679   307  1758 D Codec2Client: setOutputSurface -- generation=314369 consumer usage=0x900
11-08 12:49:22.680   278   634 I C2VdaBqBlockPool: Producer (Surface) is going to switch... ( 0x0 -> 0x6af00000003 )
11-08 12:49:22.686  1711  1727 E BufferQueueProducer: [SurfaceView[com.android.gallery3d/com.android.gallery3d.app.MovieActivity]#3(BLAST Consumer)3](id:6af00000003,api:3,p:307,c:1711) connect: already connected
 (cur=3 req=1095910144)
11-08 12:49:22.687   307  1758 D Codec2Client: Surface configure completed
11-08 12:49:22.688   307  1757 W ResourceManagerService: Ignoring request to add new resource entry with value <= 0
11-08 12:49:22.690   307  1757 W MediaCodec: mapFormat: no mediaType information
11-08 12:49:22.690   307  1757 D CCodecConfig: no recognized params in: Dict {
11-08 12:49:22.690   307  1757 D CCodecConfig:   c2::float algo.rate.value = 4
11-08 12:49:22.690   307  1757 D CCodecConfig:   c2::float ctrl.operating-rate.value = 4
11-08 12:49:22.690   307  1757 D CCodecConfig: }
11-08 12:49:22.695   278   278 D C2Store : Using ION
11-08 12:49:22.695   278   278 E ion     : ioctl c0044901 failed with code -1: Inappropriate ioctl for device
11-08 12:49:22.695   278  1759 I V4L2Decoder: Set state Idle => Decoding
11-08 12:49:22.702   278  1759 E V4L2Device: (OUTPUT_MPLANE)VIDIOC_QBUF failed
11-08 12:49:22.702   278  1759 E V4L2Decoder: pumpDecodeRequest(): Failed to QBUF to input queue, bitstreamId=0
11-08 12:49:22.702   278  1759 I V4L2Decoder: Set state Decoding => Error
11-08 12:49:22.702   278  1759 E V4L2DecodeComponent: reportError(error=14)
11-08 12:49:22.702   278  1759 W V4L2DecodeComponent: Could not pump C2Work at state: ERROR
11-08 12:49:22.702   307  1042 D CCodec  : Component "c2.v4l2.avc.decoder" returned error: 0xe
11-08 12:49:22.703   278   278 E V4L2DecodeComponent: Could not queue at state: ERROR
11-08 12:49:22.700     0     0 E         : contiguous chunk is too small 393216/786432
11-08 12:49:22.704   307  1757 W MediaCodec: Log queueInputBuffer error: 1
11-08 12:49:22.704   307  1757 E MediaCodec: Codec reported err 0x80000000, actionCode 0, while in state 6/STARTED
11-08 12:49:22.706   307  1757 D SurfaceUtils: disconnecting from surface 0xf15c1948, reason disconnectFromSurface
11-08 12:49:22.706   307  1756 E NuPlayerDecoder: onInputBufferFetched: queueInputBuffer failed for [c2.v4l2.avc.decoder] (err=1, )
11-08 12:49:22.706   307  1042 D PipelineWatcher: onInputBufferReleased: frameIndex not found (2); ignored
11-08 12:49:22.706   307  1753 E NuPlayer: received error(0x1) from video decoder, flushing(0), now shutting down
11-08 12:49:22.706  1711  1739 E MediaPlayerNative: error (1, 1)
11-08 12:49:22.707  1711  1711 E MediaPlayer: Error (1,1)
11-08 12:49:22.707  1711  1711 D VideoView: Error: 1,1
11-08 12:49:22.710   307  1756 E NuPlayerDecoder: onInputBufferFetched: queueInputBuffer failed for [c2.v4l2.avc.decoder] (err=-38, )
11-08 12:49:22.710   307  1756 E NuPlayerDecoder: Decoder (video) reported error : 0x80000000
11-08 12:49:22.710   307  1753 E NuPlayer: received error(0xffffffda) from video decoder, flushing(2), now shutting down
11-08 12:49:22.711   307  1753 E NuPlayer: received error(0x80000000) from video decoder, flushing(2), now shutting down
11-08 12:49:22.711  1711  1739 E MediaPlayerNative: error (1, -38)
11-08 12:49:22.711  1711  1727 E MediaPlayerNative: error (1, -2147483648)
11-08 12:49:22.711   307  1756 E NuPlayerDecoder: failed to flush [c2.v4l2.avc.decoder] (err=-38)
11-08 12:49:22.711   307  1753 E NuPlayer: received error(0xffffffda) from video decoder, flushing(2), now shutting down
11-08 12:49:22.712  1711  1727 E MediaPlayerNative: error (1, -38)
11-08 12:49:22.712   307  1757 D CCodecBufferChannel: [c2.v4l2.avc.decoder#464] MediaCodec discarded an unknown buffer
11-08 12:49:22.713   307  1757 D CCodecBufferChannel: [c2.v4l2.avc.decoder#464] MediaCodec discarded an unknown buffer
11-08 12:49:22.717   307  1758 I hw-BpHwBinder: onLastStrongRef automatically unlinking death recipients
11-08 12:49:22.720   307  1756 D SurfaceUtils: connecting to surface 0xf15c1948, reason onShutdown
11-08 12:49:22.723  1711  1711 D CompatibilityChangeReporter: Compat change id reported: 171228096; UID 10063; state: ENABLED
11-08 12:49:22.816  1711  1711 E MediaPlayer: Error (1,-38)
11-08 12:49:22.816  1711  1711 D VideoView: Error: 1,-38
11-08 12:49:22.846  1711  1711 E MediaPlayer: Error (1,-2147483648)
11-08 12:49:22.846  1711  1711 D VideoView: Error: 1,-2147483648
11-08 12:49:22.858  1711  1711 E MediaPlayer: Error (1,-38)
11-08 12:49:22.859  1711  1711 D VideoView: Error: 1,-38

Any thoughts would this require something regarding formats and modifiers for gbm_mesa platform in minigbm? With some added formats/modifiers I get:

...
11-08 10:27:22.463   273   390 D C2Store : Using ION
11-08 10:27:22.463   273   390 E ion     : ioctl c0044901 failed with code -1: Inappropriate ioctl for device
11-08 10:27:22.463   273  2775 I V4L2Decoder: Set state Idle => Decoding
11-08 10:27:22.470     0     0 E vc_sm_cma_import_dmabuf: imported vc_sm_cma_get_buffer failed -12
11-08 10:27:22.479     0     0 E bcm2835_mmal_vchiq: vchiq_mmal_submit_buffer: vc_sm_import_dmabuf_fd failed, ret -12
11-08 10:27:22.489     0     0 E         : bcm2835-codec bcm2835-codec: device_run: Failed submitting ip buffer
11-08 10:27:22.502     0     0 E vc_sm_cma_import_dmabuf: imported vc_sm_cma_get_buffer failed -12
11-08 10:27:22.510     0     0 E bcm2835_mmal_vchiq: vchiq_mmal_submit_buffer: vc_sm_import_dmabuf_fd failed, ret -12
11-08 10:27:22.519     0     0 E         : bcm2835-codec bcm2835-codec: device_run: Failed submitting ip buffer
11-08 10:27:22.531     0     0 E vc_sm_cma_import_dmabuf: imported vc_sm_cma_get_buffer failed -12
11-08 10:27:22.540     0     0 E bcm2835_mmal_vchiq: vchiq_mmal_submit_buffer: vc_sm_import_dmabuf_fd failed, ret -12
11-08 10:27:22.551     0     0 E         : bcm2835-codec bcm2835-codec: device_run: Failed submitting ip buffer
11-08 10:27:22.562     0     0 E vc_sm_cma_import_dmabuf: imported vc_sm_cma_get_buffer failed -12
11-08 10:27:22.569     0     0 E bcm2835_mmal_vchiq: vchiq_mmal_submit_buffer: vc_sm_import_dmabuf_fd failed, ret -12
11-08 10:27:22.579     0     0 E         : bcm2835-codec bcm2835-codec: device_run: Failed submitting ip buffer

Not sure if I just broke it. :P

rsglobal commented 2 years ago

Video buffers may require additional stride / height alignments.

It may look something like this in minigbm:

--- a/gbm_mesa_driver/gbm_mesa_internals.cpp
+++ b/gbm_mesa_driver/gbm_mesa_internals.cpp
@@ -321,6 +321,12 @@ int gbm_mesa_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t

        bool scanout = (use_flags & BO_USE_SCANOUT) != 0;
        bool linear = (use_flags & BO_USE_SW_MASK) != 0;
+
+       if (use_flags & (BO_USE_HW_VIDEO_ENCODER | BO_USE_HW_VIDEO_DECODER)) {
+               width = ALIGN(width, 32);
+               height = ALIGN(height, 32);
+       }
+
        uint32_t s_format = format;
        int s_height = height;
        if (get_gbm_mesa_format(format) == 0) {
rsglobal commented 2 years ago

BTW, what is your v4l2 is using for bitstream buffers allocation? If ION, ensure you have ION_CMA kernel options enabled.

rsglobal commented 2 years ago

You can add this line into kernel to check if the lack of CMA usage is causing importing issues:

--- a/drivers/staging/vc04_services/vc-sm-cma/vc_sm.c
+++ b/drivers/staging/vc04_services/vc-sm-cma/vc_sm.c
@@ -748,6 +748,7 @@ vc_sm_cma_import_dmabuf_internal(struct vc_sm_privdata_t *private,

        /* Verify that the address block is contiguous */
        if (sgt->nents != 1) {
+               pr_err("%s: Buffer is not contiguous dma_addr %pad\n",__func__, &dma_addr);
                ret = -ENOMEM;
                goto error;
        }
KonstaT commented 2 years ago

Yeah, just saw 11-08 14:32:55.062 0 0 E : contiguous chunk is too small 196608/786432 b and increased CMA to 512M just in case. CONFIG_ION_CMA_HEAP is not enabled so will test that next, too.

KonstaT commented 2 years ago

Guess what, it works! :D Sort of at least. Still something messed up with the colors and the bottom half has a green tint/overlay or something.

rsglobal commented 2 years ago

It might be an issue with mesa3d mapper4 api getter for nv21/12 buffers.

rsglobal commented 2 years ago

Could you check 'dumpsys SurfaceFlinger' table during playback! and tell if layer is marked as DEVICE or CLIENT?

KonstaT commented 2 years ago

Recorded a video but it's too big for github to attach. https://www.dropbox.com/s/hlvcv23ejfpinn5/VID_20211108_194739.mp4?dl=0

dumpsys SurfaceFlinger is also huge, hold on.

rsglobal commented 2 years ago

There is a table in the middle . Run adb shell dumpsys SurfaceFlinger | grep drm_hwc -B 20

KonstaT commented 2 years ago
Display 0 HWC layers:
---------------------------------------------------------------------------------------------------------------------------------------------------------------
 Layer name
           Z |  Window Type |  Comp Type |  Transform |   Disp Frame (LTRB) |          Source Crop (LTRB) |     Frame Rate (Explicit) (Seamlessness) [Focused]
---------------------------------------------------------------------------------------------------------------------------------------------------------------
 SurfaceView[com.android.gallery3d/co[...]allery3d.app.MovieActivity](BLAST)#0
  rel      0 |            0 |     DEVICE |          0 |    0    0 1920 1080 |    0.0    0.0 1920.0 1080.0 |                                              [*]
---------------------------------------------------------------------------------------------------------------------------------------------------------------
 bbq-wrapper#0
  rel      0 |            0 |     DEVICE |          0 |  970  503 1003  545 |    0.0    0.0   33.0   42.0 |                                              [ ]
---------------------------------------------------------------------------------------------------------------------------------------------------------------
rsglobal commented 2 years ago

So it is on Device, which means video is sent to display without gpu processing. And color issues aren't caused by mesa3d issue. BTW, do you have latest drmhwc fixes for nv21 buffers?

KonstaT commented 2 years ago

drm_hwcomposer I'm using is https://github.com/lineage-rpi/android_external_drm_hwcomposer/tree/lineage-19.0 Pretty much inline with current main.

rsglobal commented 2 years ago

No, the fix is missing there, please upgrade

KonstaT commented 2 years ago

Which patch? In some MR? I tested patches from https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/merge_requests/161 or https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/merge_requests/162/ and it didn't work on Pi 4, got only black screen.

rsglobal commented 2 years ago

https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/merge_requests/160

KonstaT commented 2 years ago

It's there https://github.com/lineage-rpi/android_external_drm_hwcomposer/commit/875f39793ff12f95cf8bd5c66addfa14b3cf01fb

rsglobal commented 2 years ago

Ah, sorry. I forgot that github has trouble with commit sorting

KonstaT commented 2 years ago

So, a kernel issue or something else getting messed up in the pipeline?

rsglobal commented 2 years ago

Have you upgraded minigbm_gbm ?

KonstaT commented 2 years ago

Yes, minigbm is now at https://github.com/GloDroid/glodroid_forks/tree/minigbm-v0.7.0 and the stride patch from above. Nothing else.

rsglobal commented 2 years ago

Just a note that v0.7.0 was forcepushed several times and git local copy may not update it properly.