Kodi Community Forum
Solved RPi3 and RPi4 hardware decoding expectations for version 19 - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: Raspberry Pi (https://forum.kodi.tv/forumdisplay.php?fid=166)
+---- Thread: Solved RPi3 and RPi4 hardware decoding expectations for version 19 (/showthread.php?tid=355903)

Pages: 1 2 3 4 5 6 7 8


RPi3 and RPi4 hardware decoding expectations for version 19 - graysky - 2020-07-17

I recall that the goal for v19 is to make use of RPi3 and RPi4 hardware decoding via V4L to avoid the need to use branches of Kodi such as newclock5 and leia_4 by @popcornmix . I am just wondering if this is still the case.


RE: RPi3 and RPi4 hardware decoding expectations for version 19 - popcornmix - 2020-07-17

That is the plan.


RE: RPi3 and RPi4 hardware decoding expectations for version 19 - graysky - 2020-07-17

Thanks.  I just build the latest git and it does not seem enabled (I actually cannot get any thing to play back even old xvid 640x480 files).  Is there somewhere I can go to see status?


RE: RPi3 and RPi4 hardware decoding expectations for version 19 - popcornmix - 2020-07-17

Use the gbm instructions from here.
You need to have kms driver (which needs 5.4 kernel on Pi4).


RE: RPi3 and RPi4 hardware decoding expectations for version 19 - graysky - 2020-07-17

Thanks for the tip.  I will try it!  Fun weekend project.


RE: RPi3 and RPi4 hardware decoding expectations for version 19 - graysky - 2020-07-18

(2020-07-17, 19:15)popcornmix Wrote: Use the gbm instructions from here.
You need to have kms driver (which needs 5.4 kernel on Pi4).
@popcornmix - Can you share an example /etc/config.txt with me?  Perhaps I am using the incorrect kms driver.  Using this does not work.  I am building latest git now and will post a debug.log shortly).
Code:
# See /boot/overlays/README for all available options
  
gpu_mem=320
initramfs initramfs-linux.img followkernel

dtparam=audio=on
dtoverlay=vc4-fkms-v3d
EDIT: In reading through /boot/overlays/README it seems the following could work:
Code:
upstream-pi4
vc4-fkms-v3d # already tried
vc4-kms-v3d
vc4-kms-v3d-pi4



Name: upstream-pi4
Info: Allow usage of downstream .dtb with upstream kernel on Pi 4. Comprises
the vc4-kms-v3d-pi4 and dwc2 overlays.
Load: dtoverlay=upstream-pi4
Params: <None>

Name: vc4-fkms-v3d
Info: Enable Eric Anholt's DRM VC4 V3D driver on top of the dispmanx
display stack.
Load: dtoverlay=vc4-fkms-v3d,<param>
Params: cma-256 CMA is 256MB (needs 1GB)
cma-192 CMA is 192MB (needs 1GB)
cma-128 CMA is 128MB
cma-96 CMA is 96MB
cma-64 CMA is 64MB
cma-size CMA size in bytes, 4MB aligned
cma-default Use upstream's default value

Name: vc4-kms-v3d
Info: Enable Eric Anholt's DRM VC4 HDMI/HVS/V3D driver.
Load: dtoverlay=vc4-kms-v3d,<param>
Params: cma-256 CMA is 256MB (needs 1GB)
cma-192 CMA is 192MB (needs 1GB)
cma-128 CMA is 128MB
cma-96 CMA is 96MB
cma-64 CMA is 64MB
cma-size CMA size in bytes, 4MB aligned
cma-default Use upstream's default value
audio Enable or disable audio over HDMI (default "on")
noaudio Disable all HDMI audio (default "off")

Name: vc4-kms-v3d-pi4
Info: Enable Eric Anholt's DRM VC4 HDMI/HVS/V3D driver for Pi4.
Load: dtoverlay=vc4-kms-v3d-pi4,<param>
Params: cma-256 CMA is 256MB
cma-192 CMA is 192MB
cma-128 CMA is 128MB
cma-96 CMA is 96MB
cma-64 CMA is 64MB
cma-size CMA size in bytes, 4MB aligned
cma-default Use upstream's default value
audio Enable or disable audio over HDMI0 (default "on")
audio1 Enable or disable audio over HDMI1 (default "on")
noaudio Disable all HDMI audio (default "off")



RE: RPi3 and RPi4 hardware decoding expectations for version 19 - popcornmix - 2020-07-18

What kernel are you using? I'm suggesting the 5.4 kernel from rpi-update. See here.
You want dtoverlay=vc4-kms-v3d and you shouldn't need to set gpu_mem.

For hw hevc you need the ffmpeg from here.
They will be upstreamed in time, but there is still discussion over the exact v4l2/ffmpeg interface.


RE: RPi3 and RPi4 hardware decoding expectations for version 19 - popcornmix - 2020-07-18

If you just want to run a build, then milhouse's Pi4 nightly uses the v4l2/gbm style build.
(The Pi3 one still has the legacy mmal).


RE: RPi3 and RPi4 hardware decoding expectations for version 19 - graysky - 2020-07-18

@popcornmix - The kernel is 5.4.51 and the distro is Arch ARM.  I modified config.txt to be simply:
Code:
initramfs initramfs-linux.img followkernel
dtoverlay=vc4-kms-v3d

But, that did not help.  Still cannot play back.  Link to debug log with this new config.txt:  https://gist.github.com/graysky2/69dd51b557a58a64b0d9623c0c945be5

To be clear about the ffmpeg swap you mentioned... are you suggesting that I simply pull your latest commit from the popcornmix/gbm as my kodi source rather than from xbmc/master?
Code:
  cmake -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=/usr/lib \
    -DENABLE_EVENTCLIENTS=ON \
    -DENABLE_INTERNAL_FFMPEG=ON \
    -DENABLE_INTERNAL_FMT=ON \
    -DENABLE_INTERNAL_CROSSGUID=ON \
    -DENABLE_INTERNAL_FSTRCMP=ON \
    -DENABLE_INTERNAL_FLATBUFFERS=ON \
    -DENABLE_INTERNAL_SPDLOG=ON \
    -DENABLE_EVENTCLIENTS=ON \
    -DENABLE_VAAPI=OFF \
    -DENABLE_VDPAU=OFF \
    -DENABLE_OPENGL=OFF \
    -DENABLE_MYSQLCLIENT=ON \
    -Dlibdvdcss_URL="/libdvdcss-1.4.2-Leia-Beta-5.tar.gz" \
    -Dlibdvdnav_URL="/libdvdnav-6.0.0-Leia-Alpha-3.tar.gz" \
    -Dlibdvdread_URL="/libdvdread-6.0.0-Leia-Alpha-3.tar.gz" \
    -DFFMPEG_URL="/ffmpeg-4.3-Matrix-Alpha1.tar.gz" \
    -DFMT_URL="/fmt-6.1.2.tar.gz" \
    -DCROSSGUID_URL="/crossguid-8f399e8bd4.tar.gz" \
    -DFSTRCMP_URL="/fstrcmp-0.7.D001.tar.gz" \
    -DFLATBUFFERS_URL="/flatbuffers-1.11.0.tar.gz" \
    -DSPDLOG_URL="/spdlog-1.5.0.tar.gz" \
    -DCORE_PLATFORM_NAME=gbm \
    -DGBM_RENDER_SYSTEM=gles \
    ../"xbmc-commit"
  make

Doing that (currently pulling 2af33e7f68a4d5fa8cf5a096f1ca55e013e3559c. Building it ended in errors:
Code:
...
src/libavcodec/v4l2_request.c:203:5: error: ‘V4L2_PIX_FMT_NV12_COL128’ undeclared here (not in a function); did you mean ‘V4L2_PIX_FMT_NV21M’?
  203 |     V4L2_PIX_FMT_NV12_COL128,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~
      |     V4L2_PIX_FMT_NV21M
src/libavcodec/v4l2_request.c:204:5: error: ‘V4L2_PIX_FMT_NV12_10_COL128’ undeclared here (not in a function); did you mean ‘V4L2_PIX_FMT_NV12MT_16X16’?
  204 |     V4L2_PIX_FMT_NV12_10_COL128,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      |     V4L2_PIX_FMT_NV12MT_16X16
CC    libavcodec/vc1_mc.o
src/libavcodec/v4l2_request.c: In function ‘v4l2_request_set_drm_descriptor’:
src/libavcodec/v4l2_request.c:229:25: error: ‘DRM_FORMAT_P030’ undeclared (first use in this function); did you mean ‘DRM_FORMAT_P010’?
  229 |         layer->format = DRM_FORMAT_P030;
      |                         ^~~~~~~~~~~~~~~
      |                         DRM_FORMAT_P010
src/libavcodec/v4l2_request.c:229:25: note: each undeclared identifier is reported only once for each function it appears in
src/libavcodec/v4l2_request.c:229:23: warning: assignment to ‘uint32_t’ {aka ‘unsigned int’} from ‘const uint32_t *’ {aka ‘const unsigned int *’} makes integer from pointer without a cast [-Wint-conversion]
  229 |         layer->format = DRM_FORMAT_P030;
      |                       ^
src/libavcodec/v4l2_request.c:254:21: warning: comparison between pointer and integer
  254 |     if (pixelformat == V4L2_PIX_FMT_NV12_COL128) {
      |                     ^~
src/libavcodec/v4l2_request.c:260:26: warning: comparison between pointer and integer
  260 |     else if (pixelformat == V4L2_PIX_FMT_NV12_10_COL128) {
      |                          ^~
src/libavcodec/v4l2_request.c: In function ‘ff_v4l2_request_frame_params’:
src/libavcodec/v4l2_request.c:1017:45: warning: comparison between pointer and integer
1017 |         if (ctx->format.fmt.pix.pixelformat == V4L2_PIX_FMT_NV12_COL128) {
      |                                             ^~
src/libavcodec/v4l2_request.c:1020:50: warning: comparison between pointer and integer
1020 |         else if (ctx->format.fmt.pix.pixelformat == V4L2_PIX_FMT_NV12_10_COL128) {
      |                                                  ^~
distcc[29638] ERROR: compile src/libavcodec/v4l2_request.c on localhost failed
make[6]: *** [/build/kodi-rbp-git/src/kodi-build/build/ffmpeg/src/ffmpeg/ffbuild/common.mak:59: libavcodec/v4l2_request.o] Error 1
make[6]: *** Waiting for unfinished jobs....
src/libavcodec/utils.c: In function 'avcodec_flush_buffers':
src/libavcodec/utils.c:1098:5: warning: 'refcounted_frames' is deprecated [-Wdeprecated-declarations]
In file included from src/libavcodec/utils.c:45:
src/libavcodec/avcodec.h:1357:9: note: declared here
make[5]: *** [CMakeFiles/ffmpeg.dir/build.make:132: ffmpeg-prefix/src/ffmpeg-stamp/ffmpeg-build] Error 2
make[4]: *** [CMakeFiles/Makefile2:95: CMakeFiles/ffmpeg.dir/all] Error 2
make[3]: *** [Makefile:149: all] Error 2
make[2]: *** [CMakeFiles/ffmpeg.dir/build.make:134: build/ffmpeg/src/ffmpeg-stamp/ffmpeg-build] Error 2
make[1]: *** [CMakeFiles/Makefile2:4534: CMakeFiles/ffmpeg.dir/all] Error 2
make: *** [Makefile:160: all] Error 2

Building from xbmc/master with my current set of dependencies works fine. Does popcornmix/gbm require others?

Link to builld build log: https://gist.githubusercontent.com/graysky2/20c9e83132f7e89ff9474cae88010733/raw/ffd03fc22eb4671898fa6960a4d00a4ff0fe4e24/build.log


RE: RPi3 and RPi4 hardware decoding expectations for version 19 - asavah - 2020-07-18

@graysky that build failure is because of a diference between uapi headers in raspberry tree and vanilla kernel trees.

The missing defines are here https://github.com/raspberrypi/linux/blob/rpi-5.4.y/include/uapi/linux/videodev2.h#L747

Which as you can see here https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/include/uapi/linux/videodev2.h?h=v5.4.52 are missing from stable 5.4 vanilla tree.

Those defines should be in /usr/include/linux/videodev2.h

Apparently arch uses vanilla or outdated kernel sources to bootstrap linux-api-headers thus the required bits are missing.
Ask your distro maintainers.

On a side note:
When launching master with kodi ffmpeg (as opposed to rpi-patched ffmpeg) how do you start kodi as user or as root?
Try running kodi as root - if decoding (sort of) works as root then check the permissions of /dev/video* and /dev/rpivid-* nodes


RE: RPi3 and RPi4 hardware decoding expectations for version 19 - graysky - 2020-07-18

@asavah - Thanks for the detailed post.  I am looking into the differences you mentioned.

To answer your question: Arch ARM starts kodi with kodi.service running as an unprivileged "kodi" user.  We supply these udev rules that, under v18 (popcorn's leia_pi4 fork) seem to supply the kodi user with the needed permissions. 

I took your advice and replace the kodi user in the service with root and indeed, decoding works!  So new question: What is missing in that udev rule file that would account for the failure to play?


RE: RPi3 and RPi4 hardware decoding expectations for version 19 - asavah - 2020-07-18

Maybe https://github.com/RPi-Distro/raspberrypi-sys-mods/blob/master/etc.armhf/udev/rules.d/99-com.rules#L7

/dev/video* should already have have 660 root:video permissions by udev.

EDIT: I'm not sure what exactly is missing, my pi4 right now is headless and I don't have Kodi built for it atm.
You could try running kodi binary with strace under non-root user, try openning a video and see where it fails to open something in /dev/ .
Or start the service and (as root) attach strace to kodi pid.

Eg: strace -o /home/kodi/strace.log -f /path/to/your/kodi/binary
This will produce a lehghty log file, grep it for '/dev/' after exiting kodi.


RE: RPi3 and RPi4 hardware decoding expectations for version 19 - graysky - 2020-07-18

Yes, /dev/video* are as such:
Code:
% ls -lh /dev/video*  
crw-rw----+ 1 root video 81, 10 Jul 15 06:48 /dev/video10
crw-rw----+ 1 root video 81, 11 Jul 15 06:48 /dev/video11
crw-rw----+ 1 root video 81, 12 Jul 15 06:48 /dev/video12
crw-rw----+ 1 root video 81, 13 Jul 15 06:48 /dev/video13
crw-rw----+ 1 root video 81, 14 Jul 15 06:48 /dev/video14
crw-rw----+ 1 root video 81, 15 Jul 15 06:48 /dev/video15
crw-rw----+ 1 root video 81, 16 Jul 15 06:48 /dev/video16

I copied over the file you linked to /etc/udev/rules.d/100-try.rules reloaded udev but still no luck playing.  Still tons of errors like the following:
Code:
2020-07-18 20:26:42.246 T:620     ERROR <general>: CDVDVideoCodecDRMPRIME::AddData - send packet failed: Cannot allocate memory (-12)
2020-07-18 20:26:42.247 T:620     ERROR <general>: CDVDVideoCodecDRMPRIME::AddData - send packet failed: Cannot allocate memory (-12)
2020-07-18 20:26:42.248 T:620     ERROR <general>: CDVDVideoCodecDRMPRIME::AddData - send packet failed: Cannot allocate memory (-12)

The fact that running as root suggests the software is fine, and that a permissions issue is affecting it.  I believe the kodi user is in the right groups so there has to be something udev isn't assigning correctly.
Code:
% id kodi
uid=976(kodi) gid=976(kodi) groups=976(kodi),90(network),98(power),5(tty),995(audio),994(disk),993(input),990(optical),988(storage),986(video)



RE: RPi3 and RPi4 hardware decoding expectations for version 19 - asavah - 2020-07-18

Hmm, looks like something drm related.


RE: RPi3 and RPi4 hardware decoding expectations for version 19 - asavah - 2020-07-18

As a wild guess try
chmod 666 /dev/dri/card*
chmod 666 /dev/dri/render*

However I'm not sure if gbm will work as non root because some drm ioctls require root (that's kernel stuff).
Someone with more expertise than me is needed to shed some light on this issue.