Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDR tone mapping for flatbuffers #215

Merged
merged 10 commits into from
Feb 27, 2022

Conversation

chbartsch
Copy link
Contributor

Summary
Introduces HDR tone mapping for flatbuffers input.

In some cases (depending on TV modell / capturing library in use) PicCap (Hyperion Sender App on LG TVs) is sending dim/pale images when HDR/Dolby Vision content is playing. Tone mapping helps to get this image data back to "normal".

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

  • Bugfix
  • 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:
Before:
before
After:
after

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

  • Yes
  • 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:

  • 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
  • No, couldn't find CHANGELOG.md

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:

@chbartsch chbartsch changed the title Flatbuffers with tone mapping HDR tone mapping for flatbuffers Feb 19, 2022
@awawa-dev
Copy link
Owner

awawa-dev commented Feb 23, 2022

Hi
Just as we talked before, automatic merge was not possible but as I promised I prepared your commits to be able to merge and put them on to new branch https://github.com/awawa-dev/HyperHDR/tree/chbartsch-flatbuffers Github action should compile them soon. Take a look at the result. You will be remained as an author. After initial testing I only found one small issues and corrected it: even if HDR tone mapping was disabled for flatbuffers, when the user enables it globally then the flatbuffers loads the LUT table anyway. Decide if we merge that branch later or you prefer some other solution like using re-baseing to refresh your branch to HyperHDRr's current master.

@chbartsch
Copy link
Contributor Author

Hi Just as we talked before, automatic merge was not possible but as I promised I prepared your commits to be able to merge and put them on to new branch https://github.com/awawa-dev/HyperHDR/tree/chbartsch-flatbuffers Github action should compile them soon. Take a look at the result. You will be remained as an author.
Nice! Thanks! Will try the actions output tonight.

After initial testing I only found one small issues and corrected it: even if HDR tone mapping was disabled for flatbuffers, when the user enables it globally then the flatbuffers loads the LUT table anyway. Decide if we merge that branch later or you prefer some other solution like using re-baseing to refresh your branch to HyperHDRr's current master.
I just rebased to your master but I'm not sure if that went well. Now my PR shows 722 files changed?!

@awawa-dev
Copy link
Owner

I fixed the commit tree. Should be OK now. I need apply some other minor fixes from my branch (missing include on macos, unnecessary activation of HDR if its disable for flatbuffers, move translation items on the end of file for automatic google translator) and test it on other systems.

@awawa-dev awawa-dev merged commit f426758 into awawa-dev:master Feb 27, 2022
@chbartsch
Copy link
Contributor Author

I fixed the commit tree. Should be OK now. I need apply some other minor fixes from my branch (missing include on macos, unnecessary activation of HDR if its disable for flatbuffers, move translation items on the end of file for automatic google translator) and test it on other systems.

Hey, thanks for fixing the stuff! I was kind of aware of the global HDR switching flatbuffers HDR regardless of it's HDR setting. I was just not sure how this is or should be handled with USB grabber. Maybe introduce a seperate JSON-API-Endpoint for flatbuffers HDR?

@chbartsch
Copy link
Contributor Author

Oh, just realized that you already merged it.. :)

@awawa-dev
Copy link
Owner

Yes, it's merged. Already tested it and works fine - thank you. Global HDR switch activate/disactivate flatbuffer tone mapping now but only when the flatbuffer's tone mapping option is enabled.

@chbartsch
Copy link
Contributor Author

Very nice! Thanks!!

@awawa-dev
Copy link
Owner

awawa-dev commented Mar 23, 2022

Hi @chbartsch

Since HyperHDR can run now on LG webOS with the minimal setup and with the latest commit it also support Unix Domain Socket (QLocalSocket), could you consider to implement local socket in your unicapture branch?

The performance should be great and there is no need for direct connection between HyperHDR and local libraries.
obraz

@chbartsch
Copy link
Contributor Author

Hi @awawa-dev,

first things first: 'unicapture' is not my branch but Infowski's (openlgtv discord). I just added some small parts into it. Then I made a branch for the HyperHDR-Auto-Switching which is based on unicapture.

Regardless, I could setup another branch and try to support unix sockets.

Do you plan to integrate building of HyperHDR for LG into github CI?

@awawa-dev
Copy link
Owner

awawa-dev commented Mar 24, 2022

Thank you @chbartsch for the clarification.
I think that preferable solution would be an external project (not necessarily mine) that will provide ready to use CI build of HyperHDR and your version of the unicapture (HyperHDR-Auto-Switching) backend as 'all in one' installer for a stand alone setup. I will take a look into HyperHDR-Auto-Switching branch to see if I can help. Is there any manual or short info about how to compile it (for webOS)?

@chbartsch
Copy link
Contributor Author

chbartsch commented Mar 24, 2022

I used this NDK: https://github.com/webosbrew/meta-lg-webos-ndk and build it on Linux using vscode: https://github.com/webosbrew/meta-lg-webos-ndk#vs-code

But how did you build HyperHDR for webOS then?

@awawa-dev
Copy link
Owner

I didn't build it myself ;) For HyperHDR you will probably need this: https://github.com/openlgtv/buildroot-nc4/releases (arm-webos-linux-gnueabi_sdk-buildroot.tar.gz ) I thing I've got it now, can be use for building of HyperHDR & your branch. Will prepare github CI script for the branch.

@awawa-dev
Copy link
Owner

OK, unicapture migrated to the new toolchain. Must test it later:
https://github.com/awawa-dev/capturing-webos/blob/unicapture_video-mode-switcher-socket/.github/workflows/release.yml
https://github.com/awawa-dev/capturing-webos/releases/tag/v1.0.0.0
Next step add sockets and compile HyperHDR in the same action.

@chbartsch
Copy link
Contributor Author

Very nice. Maybe I will find time over the weekend to try building hyperhdr for webOS.

@chbartsch
Copy link
Contributor Author

I didn't build it myself ;) For HyperHDR you will probably need this: https://github.com/openlgtv/buildroot-nc4/releases (arm-webos-linux-gnueabi_sdk-buildroot.tar.gz ) I thing I've got it now, can be use for building of HyperHDR & your branch. Will prepare github CI script for the branch.

No luck unfortunately. I'm able to build capturing-webos with this SDK but not HyperHDR. Have you managed to do so? Any advise on how to?

@awawa-dev
Copy link
Owner

I didn't build it myself ;) For HyperHDR you will probably need this: https://github.com/openlgtv/buildroot-nc4/releases (arm-webos-linux-gnueabi_sdk-buildroot.tar.gz ) I thing I've got it now, can be use for building of HyperHDR & your branch. Will prepare github CI script for the branch.

No luck unfortunately. I'm able to build capturing-webos with this SDK but not HyperHDR. Have you managed to do so? Any advise on how to?

How do you invoke cmake to configure build of HyperHDR and what's in the problematic output?

@chbartsch
Copy link
Contributor Author

$ cmake -DCMAKE_TOOLCHAIN_FILE=/opt/arm-webos-linux-gnueabi_sdk-buildroot/share/buildroot/toolchainfile.cmake -DCMAKE_BUILD_TYPE=Release ..
-- CMake Version: 3.16.3
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Check for working C compiler: /opt/arm-webos-linux-gnueabi_sdk-buildroot/bin/arm-webos-linux-gnueabi-gcc
-- Check for working C compiler: /opt/arm-webos-linux-gnueabi_sdk-buildroot/bin/arm-webos-linux-gnueabi-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /opt/arm-webos-linux-gnueabi_sdk-buildroot/bin/arm-webos-linux-gnueabi-g++
-- Check for working CXX compiler: /opt/arm-webos-linux-gnueabi_sdk-buildroot/bin/arm-webos-linux-gnueabi-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at CMakeLists.txt:28 (message):
  Found CCache but env settings: CCACHE_DIR is not set.  Skipping.


-- QT version 6 not found. Searching for QT version 5 instead.
-- Found Qt Version: 5.15.2
-- Debian version:
-- PLATFORM is not defined, evaluated platform: rpi
-- PLATFORM: rpi
CMake Error at CMakeLists.txt:158 (message):
  GLdispatch library not found.  Install libglvnd-dev


-- Configuring incomplete, errors occurred!

I already don't know what PLATFORM to use..

@awawa-dev
Copy link
Owner

awawa-dev commented Mar 27, 2022

PLATFORM is OK. But probably it won't compile anyway if you build it on x64 because of flatbuffer compiler, unless you build it for x64 manually. It's recommend to build it in the modified HyperHDR github action (one of matrix is using QEMU docker aarch64 image so it avoids that problem). Other options to consider: -DENABLE_V4L2=OFF -DENABLE_SOUNDCAPLINUX=OFF -DENABLE_SPIDEV=OFF -DENABLE_BOBLIGHT=OFF -DENABLE_AVAHI=OFF

that line (CMakeLists.txt:158) can be commented out or you can change PLATFORM to linux (but then it's neccesery to SET ( DEFAULT_X11 OFF ) in line 79

@awawa-dev
Copy link
Owner

awawa-dev commented Mar 27, 2022

I've managed to compile it also on x64.
Latest commit contains the changes that I mentioned earlier which addresses these specific problems.
Compile it with:

cmake -DCMAKE_TOOLCHAIN_FILE=../../webos/build/toolchain/arm-webos-linux-gnueabi_sdk-buildroot/share/buildroot/toolchainfile.cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_V4L2=OFF -DENABLE_SOUNDCAPLINUX=OFF -DENABLE_SPIDEV=OFF -DENABLE_BOBLIGHT=OFF -DENABLE_AVAHI=OFF -DPLATFORM=linux ..

You also need to set CMAKE_TOOLCHAIN_FILE for your path and install flatbuffers compiler on your host (sudo apt install flatbuffers-compiler) That's all.

obraz

After the weekend of piccap testing I have seriously doubts: the performance(lag) in significant worse than setup based on fast USB grabber. The LED is behind the LEDs about 0.5 second despite using low res setting (180x90 which results in "pixelize" visible during motion on LEDs, I have 96LEDs/meter strip). Both LG and Rpi were connected using LAN cables so it's rather capturing problem/characteristic. Only libdile_vt worked and despite promised 60FPS I only received 30FPS. But I think colors reproduction with LUT table (was updated today again, there were too much red for my taste) is great.

@chbartsch
Copy link
Contributor Author

PLATFORM is OK. But probably it won't compile anyway if you build it on x64 because of flatbuffer compiler, unless you build it for x64 manually. It's recommend to build it in the modified HyperHDR github action (one of matrix is using QEMU docker aarch64 image so it avoids that problem). Other options to consider: -DENABLE_V4L2=OFF -DENABLE_SOUNDCAPLINUX=OFF -DENABLE_SPIDEV=OFF -DENABLE_BOBLIGHT=OFF -DENABLE_AVAHI=OFF

that line (CMakeLists.txt:158) can be commented out or you can change PLATFORM to linux (but then it's neccesery to SET ( DEFAULT_X11 OFF ) in line 79

Ah OK, I would have though using a toolchain would defeat the need of compiling on the target platform. But wait, is the image Linux-bullseye-arm-aarch64-DEB-installer already the one that works on LG TV? Than I will use this one for a first test :D

@chbartsch
Copy link
Contributor Author

After the weekend of piccap testing I have seriously doubts: the performance(lag) in significant worse than setup based on fast USB grabber. The LED is behind the LEDs about 0.5 second despite using low res setting (180x90 which results in "pixelize" visible during motion on LEDs, I have 96LEDs/meter strip). Both LG and Rpi were connected using LAN cables so it's rather capturing problem/characteristic. Only libdile_vt worked and despite promised 60FPS I only received 30FPS. But I think colors reproduction with LUT table (was updated today again, there were too much red for my taste) is great.

I'm somewhat confused about the setups your are talking about/comparing here. So USB Grabber is faster then piccap in your case? I only see a tiny lag in my setup. But this is with "external" HyperHDR and WLED via Wifi at the moment. So i think the tiny lag I'm seeing is mostly from the Wifi connection to the WLED device.

Then you say "LG and Rpi". What is the Rpi actually doing here after HyperHDR runs on the TV?

@awawa-dev
Copy link
Owner

With Ezcap 321 I don't have any lag (confirmed by capturing tv/led reaction using high-framerate recording using phone). With piccap the lag is very annoying on C9. Maybe because I've got reference from other fast system and I'm sensitive to this delay. Since my LED strip is not capable to be driven remotly (I'm not using WLED or something similar) the piccap was tested using classic configuration: piccap on LG and flatbuffer client on Rpi. Because only cable connection was used for such low resolution I doubt it's a communication problem. Maybe it's specific for C9, who knows.

After I committed latest changes, it took me also some time to gather all necessary libraries to run HyperHDR (compiled on x64) on webOS. But hey, seems it's working:
obraz

@awawa-dev
Copy link
Owner

awawa-dev commented Mar 29, 2022

FYI, modified the backend and unix domain socket works just fine now.
obraz
Must revert to main branch: unicapture refuses to screencapture on my C9, even original test application can't capture it (ran it without service, maybe that's the reason but registering one is too complicated just for testing). Probably just leave it as it is, because now I'm returning to previous USB grabber setup.

@chbartsch
Copy link
Contributor Author

Hi awawa, in the meantime I was able to build HyperHDR for WebOS. Just had to use the libs (QT stuff and so on) provided by https://www.dropbox.com/s/zdxchc7uobf9j3g/HYPERHDR%26backendsHDR_ENG.pdf?dl=0 package.

Since the install packages above still use Flatbuffers and your backend repo seams to be gone: Is the unix socket approach dead now?

@awawa-dev
Copy link
Owner

awawa-dev commented Apr 3, 2022

Hi
I removed root from TV so can't support it any longer. And as I wrote earlier their is some serious problem with capturing at least on C9 that does not produce good result: the lag is too high, even if all the stuff is running locally. Don't know if it's specific for C9 but generally all of the software capturing is less or more burdened with a latency problem and I met a very high lag where I expected a lag from the network communication rather. Also flatbuffer packaging could be also dropped for local socket which should simpler the backend project and the communication but it won't improve the main problem - it's just a idea.

HyperHDR can run without some of the libraries from the collection and without some quirks (it's made for Hyperion) but its not a big problem. I've archived the patches with modified backend using local sockets, it was tested and it's working (at least mainline, unicaptures could not be tested because it refused to screencapture a valid frame but it's the same socket routine) and can be provided but as I remarked I prefer it to be maintain outside the HyperHDR.

@chbartsch
Copy link
Contributor Author

OK, thanks for the clarification. There are more people on the openlgtv discord having problems with latest unicapture on C9 TVs I think. But if you're happy with your USB-capture setup so be it. ;)

I don't think unix socket will do much (if any) to the latency so it's not super urgent to me at the moment. I'm currently occupied with other projects - maybe will come back to it later..

chbartsch added a commit to chbartsch/HyperHDR that referenced this pull request Nov 29, 2022
* intermediate state

* loading lut table works

* introduced flatbuffers tone mapping setting

* set tone mapping with global switch

* cleanup

* account for OS dependent LUT file paths

* cleanup

* rebased

* fixes

* fix flatbuffer server activation

Co-authored-by: Awawa <mail4awawa@gmail.com>
chbartsch pushed a commit to chbartsch/HyperHDR that referenced this pull request Nov 29, 2022
Windows/Unix domain sockets offer much higher performance than TCP, can be used by external grabbers
Local server name is: hyperhdr-domain

awawa-dev#215 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants