hyperion.ng icon indicating copy to clipboard operation
hyperion.ng copied to clipboard

[WIP] DRM Grabber

Open Paulchen-Panther opened this issue 2 years ago • 35 comments

Summary

I'll spare myself the many words and refer you to the Issue. Everything is still WIP and miles away from the result. Issue: #983

To build this PR follow the steps in the CompileHowto and install libdrm-dev as an additional dependency. To add the DRM grabber to the current build you should also pass -DENABLE_DRM=ON as cmake argument.

What kind of change does this PR introduce? (check at least one)

  • [ ] Bugfix
  • [x] Feature
  • [ ] Code style update
  • [ ] Refactor
  • [ ] Docs
  • [ ] Build-related changes
  • [ ] Other, please describe:

If changing the UI of web configuration, please provide the before/after screenshot:

Does this PR introduce a breaking change? (check one)

  • [ ] Yes
  • [x] No

If yes, please describe the impact and migration path for existing setups:

The PR fulfills these requirements:

  • [ ] When resolving a specific issue, it's referenced in the PR's body (e.g. Fixes: #xxx[,#xxx], where "xxx" is the issue number)

If adding a new feature, the PR's description includes:

  • [x] A convincing reason for adding this feature
  • [ ] Related documents have been updated (docs/docs/en)
  • [ ] Related tests have been updated

PLEASE DON'T FORGET TO ADD YOUR CHANGES TO CHANGELOG.MD

  • [ ] Yes, CHANGELOG.md is also updated

To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.

Other information:

Paulchen-Panther avatar Jan 29 '22 21:01 Paulchen-Panther

Hello @Paulchen-Panther :wave:

I'm the Hyperion Project Bot and I want to thank you for contributing to Hyperion with your pull requests!

To help you and other users test your pull requests faster, I'll create a link for you to your workflow artifacts.

:link: https://github.com/hyperion-project/hyperion.ng/actions/runs/1766823566

Of course, if you make changes to your PR, I will create a new link.

Best regards, Hyperion Project

hyperion-project[bot] avatar Jan 29 '22 21:01 hyperion-project[bot]

Thanks a lot for the PR!

Can you give a (quick) overview what is still not working or what might break? This would help to decide, if one wants to try it out or not.

tefracky avatar Jan 30 '22 09:01 tefracky

I have already done this in the forum. In German language. But a translator should help. (Google/DeepL/ etc.)

https://hyperion-project.org/forum/index.php?thread/10463-install-hyperion-ng-on-libreelec-x86-64-rpi-inoffiziell-unofficially/&postID=43192#post43192

Paulchen-Panther avatar Jan 30 '22 09:01 Paulchen-Panther

Some first feedback. This works on my rpi4 running Arch Linux. For testing AUR PKBUILD see below.

I did playback of some local video as well as a youtube video from within Kodi.

You need to the select Output 1, otherwise you get the error:

Grabber disabled, device 'DRM' signals error: 'Unable to get DRM resources on /dev/dri/card0'

Even if you switch back to Output 1 I had to restart hyperiond.

If you enable the "Live Video" on LED Visualization, you can see that grabbing is working.

For the records, I noticed when Kodi menu is active, aka no playback, this is used as input as well. But that seems to be an unrelated thing.

I'm currently on some small improvements regarding CMake and will add suggestions to this PR later

Updated PKGBUILD which shall replace the one from AUR. PKGBUILD.txt

AlexanderStein avatar Jan 30 '22 10:01 AlexanderStein

Hey @Paulchen-Panther I created a new link to your workflow artifacts: :link: https://github.com/hyperion-project/hyperion.ng/actions/runs/1768451756

hyperion-project[bot] avatar Jan 30 '22 10:01 hyperion-project[bot]

@AlexanderStein Thanks again for your suggestions. I will push the fixes right away. The last commit was by mistake. Force push comes immediately.

Paulchen-Panther avatar Jan 30 '22 13:01 Paulchen-Panther

Hey @Paulchen-Panther I created a new link to your workflow artifacts: :link: https://github.com/hyperion-project/hyperion.ng/actions/runs/1768817228

hyperion-project[bot] avatar Jan 30 '22 13:01 hyperion-project[bot]

Hey @Paulchen-Panther I created a new link to your workflow artifacts: :link: https://github.com/hyperion-project/hyperion.ng/actions/runs/1768839124

hyperion-project[bot] avatar Jan 30 '22 14:01 hyperion-project[bot]

Is this PR works with 4K configuration on libreelec ?

rjousse18 avatar Feb 14 '22 08:02 rjousse18

Is this PR works with 4K configuration on libreelec ?

Not yet.

Paulchen-Panther avatar Feb 14 '22 15:02 Paulchen-Panther

I merged the change request and tried to compile the code on a RasPi3 with OSMC installed. I followed the manual compiling instruction according to https://github.com/hyperion-project/hyperion.ng/blob/master/doc/development/CompileHowto.md#the-detailed-way-with-many-comments. As cmake options I used: cmake -DCMAKE_BUILD_TYPE=Release -DPLATFORM=rpi -DENABLE_DEV_SPI:BOOL=ON -DENABLE_DRM=ON -DENABLE_FB=ON ..

Unfortunately, I always end up with the following error when compiling: [ 58%] Building CXX object libsrc/api/CMakeFiles/hyperion-api.dir/JsonAPI.cpp.o In file included from /home/osmc/hyperion-jumper/libsrc/api/JsonAPI.cpp:59: /home/osmc/hyperion-jumper/include/grabber/DRMFrameGrabber.h:95:21: error: ‘drmModeFB2Ptr’ was not declared in this scope std::map<uint32_t, drmModeFB2Ptr> framebuffers; ^~~~~~~~~~~~~ /home/osmc/hyperion-jumper/include/grabber/DRMFrameGrabber.h:95:21: note: suggested alternative: ‘drmModeFBPtr’ std::map<uint32_t, drmModeFB2Ptr> framebuffers; ^~~~~~~~~~~~~ drmModeFBPtr /home/osmc/hyperion-jumper/include/grabber/DRMFrameGrabber.h:95:34: error: template argument 2 is invalid std::map<uint32_t, drmModeFB2Ptr> framebuffers; ^ /home/osmc/hyperion-jumper/include/grabber/DRMFrameGrabber.h:95:34: error: template argument 4 is invalid make[2]: *** [libsrc/api/CMakeFiles/hyperion-api.dir/build.make:106: libsrc/api/CMakeFiles/hyperion-api.dir/JsonAPI.cpp.o] Fehler 1 make[1]: *** [CMakeFiles/Makefile2:3095: libsrc/api/CMakeFiles/hyperion-api.dir/all] Fehler 2 make[1]: *** Es wird auf noch nicht beendete Prozesse gewartet....

Is that something that needs to be fixed in the pull request or did I miss a step when compiling the code?

Jumper78 avatar Feb 19 '22 12:02 Jumper78

Your libDRM library does not seem to know the struct drmModeFB2Ptr. Which version is installed under OSMC?

Paulchen-Panther avatar Feb 19 '22 13:02 Paulchen-Panther

OSMC is still based on Debian Buster and uses libdrm 2.4.97-1. You are right, that could be the reason. I need to double check later.

Jumper78 avatar Feb 19 '22 13:02 Jumper78

I assume that you have ignored this cmake point. 😄 https://github.com/hyperion-project/hyperion.ng/blob/69e99e09d657a7a3a7498e5f5cdedbea713f05ea/libsrc/grabber/drm/CMakeLists.txt#L5

Paulchen-Panther avatar Feb 19 '22 13:02 Paulchen-Panther

OSMC is still based on Debian Buster and uses libdrm 2.4.97-1. You are right, that could be the reason. I need to double check later.

But you can install the libDRM from Debian Buster Backports. This should allow it to compile.

sudo echo deb http://deb.debian.org/debian buster-backports main >> /etc/apt/sources.list
sudo apt-get update
sudo apt-get -t buster-backports -y --no-install-recommends install libdrm-dev

Paulchen-Panther avatar Feb 19 '22 13:02 Paulchen-Panther

Thank you very much, that did the trick! I am actually not sure if OSMC has already changed to Bullseye for fresh installations. It might even be that I am just stuck on Buster due to automatic updates not updating the underlying OS.

Hyperion with DRM works perfectly fine for most video sources now. That is great work! I do have some TV stations, though, that show an error due to "format YU12". Is there any chance to get that working as well at some day in the future or are there limitations in the underlying libraries?

Jumper78 avatar Feb 19 '22 17:02 Jumper78

Thank you for the feeback. I will do my best to fix the reported bugs. For that I would need a full verbose debug log from you. You can turn on the Verbose mode in the code. Additionally, it would be helpful if you could provide me with the format of the video source.

Paulchen-Panther avatar Feb 19 '22 17:02 Paulchen-Panther

Setting the constant verboseto true and then running hyperiond with the option -d (for debug) gives me the following lines when running the video file in Question: 2022-02-19T20:15:11.278 |__| DRM : <DEBUG> DRMFrameGrabber.cpp:175:grabFrame() | Framebuffer ID: 210 - Width: 720 - Height: 576 - DRM Format: YU12 - PixelFormat: I420 2022-02-19T20:15:11.279 |__| DRM : <ERROR> Format: YU12 failed. Error: Invalid argument 2022-02-19T20:15:11.338 |__| DRM : <DEBUG> DRMFrameGrabber.cpp:175:grabFrame() | Framebuffer ID: 211 - Width: 720 - Height: 576 - DRM Format: YU12 - PixelFormat: I420 2022-02-19T20:15:11.339 |__| DRM : <ERROR> Format: YU12 failed. Error: Invalid argument

The following screenshot shows what VLC tells me about the video-stream codecs in the video-file: Screenshot 2022-02-19 at 20 25 30

It is reproducible with recorded video files. So, if it helps you, I could provide you a small recorded part of the video stream.

Jumper78 avatar Feb 19 '22 19:02 Jumper78

It is reproducible with recorded video files. So, if it helps you, I could provide you a small recorded part of the video stream.

Thank you very much for your help. 👍 Indeed, this would be helpful in further developing this PR.

Paulchen-Panther avatar Feb 20 '22 12:02 Paulchen-Panther

Thank you very much for your help. 👍 Indeed, this would be helpful in further developing this PR.

Here it is: http://urlsal.at/4V1 [link has been deactivated]

Jumper78 avatar Feb 20 '22 13:02 Jumper78

Thank you very much for your help. 👍 Indeed, this would be helpful in further developing this PR.

Here it is: http://urlsal.at/4V1 [link has been deactivated]

I did a little testing with your sample video and it looks like it is in interlace format. The data can only be accessed via shared memory which was not the case until now. As soon as I manage to get a clear picture I will get back to you. Thanks again for your support. P.S. I'm sorry to get back to you so late. I have a lot on my mind right now.

Proof: image

Paulchen-Panther avatar Feb 28 '22 19:02 Paulchen-Panther

I would like to know when this PR will be adopted? I'm really looking forward to this feature.

ReWiG avatar Apr 12 '22 06:04 ReWiG

Somewhat related to this topic: What is the best way to get this compiled for Libreelec? I tried compile_le.sh from https://hyperion-project.org/forum/index.php?thread/10753-compile-hyperion-ng-on-libreelec/ and changing the git clone source to this branch of this repo. However, this gets stuck at "Sending build context to Docker daemon" and just loading more and more data. Unless the build context is actually larger than 10 GB, then I might have just been impatient ;)

witty91 avatar Apr 12 '22 20:04 witty91

I built Paulchen-Panther drm branch with drm enabled. Drm can be selected with output1, but it always stays solid black (No matter if in the main menu or playing some video.) Running on a rpi4 with kodi 19 (standalone, raspios), windowing system is gbm, fullhd, no hdr. In the logs there is only an entry, that the grabber is running.

m4rkusxxl avatar Apr 16 '22 13:04 m4rkusxxl

I'm not sure I understand this reply correctly. You mean to compile hyperion.ng on libreelec itself? I don't think it has the build tools for that, that's where I'm currently stuck with this. But I also don't want to spam this thread here, I might just install kodi on a more full underlying OS and compile there.

witty91 avatar Apr 16 '22 18:04 witty91

Probably I am facing a permission problem: When hyperion is started as root, I see the captured screen, but when it is running as user pi (default systemd script from repo does it like that. Same when I manually run in console.) I only get a black screen. I see nothing suspicious in the logs, verbose is active and DRM just outputs some "grabFrame() | Framebuffer ID: 343 - Width: 1920 - Height: 1080 - DRM Format: XR24 - PixelFormat: BGR32" lines.

/dev/dri/card* are rw for group "video", which pi is a member of.

Any ideas what else is needed?

m4rkusxxl avatar May 23 '22 14:05 m4rkusxxl

1080p content seems to work: Width: 1920 - Height: 1080 - DRM Format: YU12 - PixelFormat: I420 1080p content, that does not actually have 1080 seems to work: Width: 1920 - Height: 816 - DRM Format: YU12 - PixelFormat: I420 But 720 content just gives greenish garbage: Width: 720 - Height: 402 - DRM Format: YU12 - PixelFormat: I420

Any idea?

m4rkusxxl avatar Jun 06 '22 14:06 m4rkusxxl

But 720 content just gives greenish garbage Any idea?

What's the encoding? Only H.264 seems to be working right now, at least I couldn't get H.265 or VP9 to work...

Chaphasilor avatar Jun 06 '22 14:06 Chaphasilor

720x402 is actually 480p, sorry for that. ;)

But 720 content just gives greenish garbage Any idea?

What's the encoding? Only h H.264 seems to be working right now, at least I couldn't get H.265 or VP9 to work...

Yes, both are h264 (480p is main @L3.1 and 1080p is high @L4.1)

m4rkusxxl avatar Jun 06 '22 16:06 m4rkusxxl

Mhh. I compiled it myself (with drm argument) but the option DRM wont show up in hyperion

Assassin286 avatar Sep 02 '22 21:09 Assassin286