RootMyTV.github.io icon indicating copy to clipboard operation
RootMyTV.github.io copied to clipboard

It would be nice to be able to add DTS support.

Open Zibri opened this issue 3 years ago • 65 comments
trafficstars

LG OLED CX and later TVs do not support DTS anymore.

It would be nice to add it back.

Zibri avatar Sep 08 '22 03:09 Zibri

I was just thinking about this. If it were just a software issue, and B9/C9 and BX/CX are really similar TVs, maybe we could toggle or add support...

alvgalrus avatar Sep 25 '22 00:09 alvgalrus

CX/C1 is physically able to play DTS track of mkv file. So I guess this is a software issue. Requires a furtner research on how to properly add dts support. https://www.youtube.com/watch?v=UV0gSDck9Ew

aabytt avatar Sep 30 '22 11:09 aabytt

it is indeed a software issue only.

Zibri avatar Sep 30 '22 11:09 Zibri

CX/C1 is physically able to play DTS track of mkv file. So I guess this is a software issue. Requires a furtner research on how to properly add dts support. https://www.youtube.com/watch?v=UV0gSDck9Ew

Do you mind sharing the steps to try that with a BX?

alvgalrus avatar Oct 08 '22 16:10 alvgalrus

EDIT: If you don't want to scroll through the whole thread, you can always access the latest release of dts_restore by clicking this button: Download Stats

INITIAL DISCLAIMER

Playing with root and system libraries or partitions is NEVER without a risk, and I make no guarantee whatsoever that, whereas what I am describing below does appear to works fine for my specific environment, you are not going to end up bricking your TV.

THE FOLLOWING IS THEREFORE PROVIDED "AS IS", WITHOUT GUARANTEE OF ANY KIND, AND THE ENTIRE RESPONSIBILITY OF USING THE FOLLOWING DATA, FOR ANY PURPOSE, IS ENTIRELY WITH YOU

In other words: If you don't understand what is being described below, you REALLY shouldn't play with it, because this is pretty much only a proof of concept that will NOT achieve what you expect. Instead you should wait until a safer solution, that has both been validated properly and is easier to install, comes along as what I am providinging below is mostly intended for developers or experienced users.

YOU HAVE BEEN WARNED!

Reenabling DTS on LG TVs

DTS can most certainly be reenabled.

As a matter of fact, I can give you limited DTS support right now, if you have root access:

dts_install.tar.gz

Just extract the content of the above archive to /home/root/ (you should end up with a /home/root/dts_install.sh and a /home/root/gst/ directory), run dts_install.sh and you should now be able to play mkv's with DTS tracks...

However, this comes with the following major caveats:

  1. DTS output is limited to 2 channels WITH NO DOWNMIX, so you can say goodbye to dialog or surround if you have anything that uses center or rear channels (I told you it was limited DTS support).
  2. No DTS passthrough.
  3. You're going to lose the ability to play mkv's and possibly other video files at 2x speed, regardless of whether they include a DTS track or not.
  4. I have only tested this on OLED CX, so YMMV.

In short, this mostly provides a demonstration of how DTS could be restored, for people who might be interested to take it further...

How it works

Basically, we replace all the GStreamer libraries that LG has deliberately nerfed with "unnerfed" versions (and if you are interested in recompiling your own version, rather than use the ones I provide, I'm describing how to do that below). Especially, we:

  • Restore DTS demuxing in the Matroska parsing library (libgstmatroska.so)
  • Restore DTS parsing in the global audio parsing library (libgstaudioparsers.so)
  • Restore DTS decoding in the ffmpeg based global software decoding library (libgstlibav.so)

Then we refresh the GStreamer registry (which is permanent on LG hardware and is not refreshed unless you specifically ask for it) and make sure avdec_dca (the libgstlibav.so DTS decoder) has a high enough priority in /etc/gst/gstcool.conf, the global GStreamer configuration file used by LG.

What about the limitations?

As far as I can tell, the first 2 limitations (2.0 audio with no downmix, and no passthrough) is due to LG having shoved their feature-complete audiosink (multichannel with passthrough) behind their proprietary audio decoder library. So, if you don't go through these proprietary decoders, you're limited to the default 2.0 audio. Even with stock unaltered firmware, you can actually observe the same issue (only the front channels of 5.1 or 7.1 audio being output) if you play something like a mkv with 5.1 or 7.1 FLAC audio, on account that this kind of configuration never reaches the more capable multichannel audio sink, most likely because this is handled by the non-proprietary FLAC decoder. As a matter of fact, LG does some weird gymnastic in hiding some of its A/V processing chain behind a proxy (decproxy) and fake decoders(fakedec). For more on this see https://github.com/justinjoy/gst-plugins-cool.

Note that I have also tried the dtsdec from gst-plugins-bad instead of libav (which comes with its own whole set of challenges... there's a good reason the GStreamer folks have placed it in the "bad" plugins repository), and the outcome about 2.0 audio without passthrough being the only option available appears to be the same.

So, this may very well mean that the best we can ever hope to achieve using the "insert our own DTS decoder here" approach is stereo downmix... unless we start hacking at the proprietary libgstlxaudiodec.so/libgstlxaudiosink.so libraries...

However, there still exists another approach, that should allow us to achieve full multichannel DTS, which is to write our own DTS → LPCM converter (basically audio/x-private1-dts → /audio/x-private-ts-lpcm), since the latter is something that the LG processing chain should happily output as 5.1 or 7.1 on account that it's one of the supported audio formats for BluRay. This latter approach may require quite a bit more involvement than simply re-enabling DTS in the libraries where LG forcefully removed it however...

The other limitation, about loss of 2x speed playback when overriding the libraries, is most likely due to the Matroska parser override. But it doesn't worry me too much at this stage, since LG should be providing us with everything we need to recompile a libgstmatroska.so similar to theirs, where we can just re-enable DTS (but please bear in mind that this will only apply to DTS parsing, not DTS decoding).

Wait, what? LG is going to give us the source for some of the libraries they nerfed?

[EDIT 2023.01.02 - As promised, LG have now released their modified GStreamer sources here and if you are interested in using them to recompile your replacement binaries, you may also wants to take a look here.]

Yes, that is exactly right.

You see, what a lot of people don't appreciate (including major companies like LG :smile:), is that the (L)GPL has actually a very well defined intent, from which the full legalese of the license is actually derived:

The (L)GPL is intended to ensure that users of software that contains (L)GPL-derived binaries can replace any of these (L)GPL-derived binaries with either an identical or modified version, that they compiled themselves. This is meant to be accomplished by ensuing that the source code, that was used to produce these (L)PGL-derived binaries, is being published by the purveyor of the software.

This is very different from MIT or BSD, where you can take the code, modify it, and never publish these modifications. With LGPL, if you make any modification of LGPL derived source, be it to add or remove a single line, and publish a binary, you MUST publish that source (and that is regardless of whether the user can actually replace the binary or not, i.e. it still applies if you sign or encrypt your firmware or prevent root access altogether).

Well, it so happens that outside of the libgstlx... specific ones, the GStreamer libraries that LG uses are derived from LGPL v2.x code, including libgstmatroska.so, libgstaudioparsers.so and libgstlibav.so, and LG has, so far, "forgotten" to publish the sources for these libraries, even though they clearly altered them to remove DTS support (Both the LGPL licensing and the alteration are very easy to demonstrate by looking at the binaries and/or disassembling them with something like Ghidra).

Which basically means that, in terms of (most of) their GStreamer libraries, LG are currently in breach of the LGPL license.

And it also happens that I have contacted their Open Source inquiry department (at https://opensource.lge.com/inquiry) to signal this legal issue to them, and they have replied that plan to publish the relevant sources (at least for CX firmware 04.40.20 which is the one I specifically asked for, even though, technically, they are supposed to publish their changes for each firmware they publish) within the next 2 weeks.

Which means that we can most likely sort the 2x playback speed issue once we compile our libraries with whatever changes LG applied and with DTS support.

And that, my friends, is why you really want developers to use (L)GPL as their license, so that, as a user, you can't end up being locked out of running your own version, and "unnerf" whatever a manufacturer decides you can or can not do...

Of course, I'll keep you posted on the publishing of the LG GStreamer sources.

What if I want to compile the libraries myself (rather than trust yours)?

Sure. You'll need a recent Linux machine with the WebOSBrew SDK installed. Then:

. /opt/webos-sdk-x86_64/1.0.g/environment-setup-armv7a-neon-webos-linux-gnueabi
git clone git://anongit.freedesktop.org/git/gstreamer/gstreamer
cd gstreamer
git checkout tags/1.14.0 -b lg
git submodule update
autoreconf -i
./autogen.sh --noconfigure
wget https://www.gentoofan.org/gentoo/misc/gst/gstreamer-1.16.2-make43.patch
patch -p1 < gstreamer-1.16.2-make43.patch
./configure --disable-gtk-doc --disable-introspection --enable-shared --disable-orc --host=arm-webos-linux-gnueabi --with-sysroot="$SDKTARGETSYSROOT" --prefix="$SDKTARGETSYSROOT"
make install

cd ..
git clone git://anongit.freedesktop.org/gstreamer/gst-plugins-good
cd gst-plugins-good
git checkout tags/1.14.0 -b lg
./autogen.sh --noconfigure
wget https://www.gentoofan.org/gentoo/misc/gst/gst-plugins-good-1.16.2-make43.patch
patch -p1 < gst-plugins-good-1.16.2-make43.patch
./configure --disable-gtk-doc --enable-shared --disable-orc --host=arm-webos-linux-gnueabi --with-sysroot="$SDKTARGETSYSROOT" --prefix="$SDKTARGETSYSROOT" CPPFLAGS="$CPPFLAGS -I$SDKTARGETSYSROOT/include"
make

cd ..
git clone git://anongit.freedesktop.org/gstreamer/gst-libav
cd gst-libav/
git checkout tags/1.14.0 -b lg
./autogen.sh --noconfigure
./configure --enable-shared --with-libav-extra-configure="--disable-everything --enable-decoder=aac --enable-decoder=dca --enable-decoder=ac3 --enable-decoder=alac --enable-decoder=amrnb --enable-decoder=amrwb --enable-decoder=eac3 --enable-decoder=flac --enable-decoder=mp3 --enable-decoder=mulaw --enable-decoder=wmapro --enable-decoder=wmav1 --enable-decoder=wmav2 --enable-decoder=wmavoice --enable-decoder=h264" --host=arm-webos-linux-gnueabi --with-sysroot="$SDKTARGETSYSROOT" --prefix="$SDKTARGETSYSROOT" CPPFLAGS="$CPPFLAGS -I$SDKTARGETSYSROOT/include"
make

At the end of this, you should find the libgstmatroska.so and libgstaudioparsers.so in gst-plugins-good/ and libgstlibav.so in gst-libav/.

Additional notes

  • If you know your bash shell, the dts_install.sh script should be pretty explicit. We just mount an override folder for /usr/lib/gstreamer-1.0/ so that we can place our libraries there and we also override /etc/gst/gstcool.conf to set the priority of avdec_dca. Note that you may want to set GST_UPDATE_REGISTRY=0 in the script after you have ran it once, so that you don't update the registry partition every time you run the script, on account that registry changes are preserved between reboots.
  • Outside of the registry update (which is benign even if avdec_dca is no longer provided from libgstlibav.so) the changes are designed not to be permanent. This means that, if anything happens, a reboot should restore everything back to normal. Be mindful that if you have Quick Start+ enabled, because the TV doesn't actually power off, changes may still persist until you perform a formal reboot or unplug the TV altogether.
  • Again, I have only tested it on an OLED CX model, so, whereas the libraries and script are built in a manner that I believe should also work for non CX users, I really can't promise anything.
  • If you are interested in seeing what's going on with the GStreamer processing, and especially how parsers and codecs are invoked, you probably want to change DEBUG_MODE=disable to DEBUG_MODE=enable in /etc/gst/gstcool.conf (or /tmp/gstcool.conf since these are the same file). Then you will get some very verbose /tmp/gst.log.# files you can examine.

pbatard avatar Dec 08 '22 19:12 pbatard

grat post! @pbatard ! Can you contact me? I think we can do a lot together.

Zibri avatar Dec 09 '22 05:12 Zibri

@pbatard great! I could play dts on CX by swapping libgstmatroska.so and libgstlibav.so with C9 libs but it worked only with gst-play. So glad you made it working.

aabytt avatar Dec 09 '22 07:12 aabytt

Here's a v2, that downmixes multichannel DTS to stereo and is therefore a lot more usable:

dts_install_v2.tar.gz

Especially, if you don't have an external decoder but just use the internal TV speakers, then the above is pretty much all you need to restore DTS playback.

Installation process is the same as before: Extract all the content to /home/root/ and run dts_install.sh. Note that you will need to manually run the script at each boot, since it's designed not to be permanent, and you probably want to change GST_UPDATE_REGISTRY=1 to GST_UPDATE_REGISTRY=0 after you ran the script at least once, as the registry is preserved between reboots.

If someone wants to write a DTS Enabler webos app, that uses this content to enable DTS automatically (and in a more friendly manner) feel free to go ahead. Obviously, that app will require root access. Ideally, since I pulled the downmix coefficients out of thin air, we'd probably want to have that potential webos app handle the downmix values and feed them to libgstlibav.so through a config file, so that users can modify them to their linking...

Notes:

  • If you still get This video does not support audio on first attempt, just close the video file and try again. Sometimes the LG player seems to be a little slow on realising that it can actually play DTS back again... 😉
  • This version does away with libgstaudioparsers.so altogether, since libgstlibav.so can include a DTS parser if you add --enable-parser=dca to the --with-libav-extra-configure= options of gst-libav (see previous entry).
  • Since I'm not LG, and I do publish my changes, here's the exact patch I applied to gst-libs/ext/libav/ (which is a git submodule that needs to be instantiated before you can patch it) to force Stereo downmix: Force-stereo-downmix-for-LG.patch.gz
  • If you have a DTS track that uses floating point rather than integer, the downmix will probably not work, since I only bothered to override fixed point. My understanding is that it should be uncommon enough so as not to be an issue.
  • Again, because we override libgstmatroska.so with a non LG version, you will lose 2x playback for all mkv files (and not just those that contain a DTS track).
  • It's still possible that we just haven't found the proper sink to use to get actual multichannel and/or passthrough and that there's some other audio sink besides the audiosink that's referenced in /etc/gst/gstcool.conf. Or possibly, there's something that need to be done (preliminary conf?) to have audiosink properly handle multichannel. If that's the case, that would avoid having to go through the whole shebang of writing our own DTS -> BluRay LPCM converter, which is likely to be a very lengthy process if it happens. So if you are interested in restoring DTS and can find your way around GStreamer, feel free to poke around.

pbatard avatar Dec 10 '22 22:12 pbatard

Just going to add that it appears that floating point DTS tracks appear to be more common than I thought, and these currently won't work, on account that the DTS codec will be trying to output audio as raw 32-bit floating point, and the default LG audio sink does not accept that. So you'll get a This file cannot be played error if the DTS track happens to be a floating point one.

It'll probably require quite a bit of time to add support for floating point DTS...

pbatard avatar Dec 11 '22 12:12 pbatard

Here's v3, with the following changes:

  • Fix playback for regular DTS files (the ones that were converted to floating point)
  • Fix rear right channels being downmixed to front left instead of front right
  • Enable the reading of the stereo downmix coefficient from /etc/gst/gstcool.conf
  • Only override the 2 libraries files we need instead of overriding the whole library directory.

dts_install_v3.tar.gz

Basically this version should play any DTS track (as long as it's embedded into a .mkv — There's no support for anything but .mkv) and what's more, if you're not happy with my stereo downmix values, you can set your own by editing the [downmix] section of /etc/gst/gstcool.conf.

From this, it should be possible (by somebody else, as I am not planning to do that myself) to create a webos app, that handles the script overrides and also allows the user to set their downmix parameters by updating /etc/gst/gstcool.conf.

As far as non multichannel DTS is concerned, this should accomplish pretty much all we need, bearing in mind that, once LG releases their libgstmatroska.so source, I am hopeful that we'll be able to fix the lost of 2x playback for all .mkv files.

I'm still not too sure about multichannel, as we have at least 3 vectors of attacks there:

  1. Figure out if there is a trick to enable multichannel and passthrough for the default LG audiosink, so that we can just feed the mulltichannel output from the decoder and have that "just work".
  2. Write our own supplement to libgstlxaudiodec.so, that mimics what the former does for ac3, but for DTS. Looking at the underlying liblxa.so, which is invoked by libgstlxaudiodec.so, I can definitely see some support for DTS there, so it's possible that duplicating what libgstlxaudiodec.so does might not require that much code, if it just feeds most of the stream to liblxa.so.
  3. Write our own DTS → BluRay LPCM converter.

As opposed to floating point DTS (which was actually very simple, since the issue was not that there exists "floating point DTS tracks", as I erroneously assumed, but that the libav decoder for regular DTS was set to output floating point PCM by default, and there was just one flag to toggle to change that), this is going to require a lot of time to figure out...

Finally, the source for the modified libgstlibav.so can be found at https://github.com/pbatard/gst-libav.

pbatard avatar Dec 12 '22 23:12 pbatard

And here we go, as a new year's present, here's a working permanent DTS restoration package for LG OLED CX.

As LG promised, they finally released the sources for GStreamer (as part of the webOS 5.0 JO_2.0_1.tar.gz archive available here, which, as I suspected, allowed me to recompile a version of libgstmatroska.so that supports 2x playback.

The nice surprise, which I wasn't really expecting, is that 2x playback also works for DTS (as long as you don't play 4k videos, but that's a global limitation that applies to AC3/AAC too).

With this sorted out, I can therefore enable a more permanent means of restoring DTS support, since there shouldn't be any loss of functionality for non DTS media.

Download

Download Stats

You can download the new archive from HERE and basically the new DTS restore process is as simple as:

  • Open a root shell to your TV (e.g. using ssh)*
  • Download, extract and run the installer by issuing:
    cd /home/root
    wget https://github.com/lgstreamer/dts_restore/releases/download/1.0/dts_restore_1.0.tgz
    tar -xzvf dts_restore_1.0.tgz
    ./dts_install.sh
    

That's it.

An uninstaller (dts_uninstall.sh) is also provided if needed, but all it does, really, since it's all that's needed, is delete the /var/lib/webosbrew/init.d/restore_dts that was created by the installer.

Oh, and this new version does not alter any of the original firmware files, such as the GStreamer registry (which we regenerate in /tmp/ on each boot and use an overlay for) and minimises RAM usage by not duplicating unnecessary content to /tmp/.

Sources

I have now moved all the sources that were used to create the content under https://github.com/orgs/lgstreamer/repositories. Especially, you will find complete details on how you can recompile your own libgstmatroska.so as well as libgstlibav.so from the sources that were released by LG.

I'm still not completely sure why, since we're using the same source and should also be using the same configure options, our libgstlibav.so is so much bigger than LG's, but I suspect this has to do with being able to locate the shared ffmpeg library in our sysroot (using LG's sysroot was too much of a hassle), and, outside of the extra space taken, I don't really see much of an issue arising from this. Plus, in case LG also nerfed their ffmpeg, this should keep us safe from surprises...

Limitations (besides root)

  • Only mkv playback supported (no .mp4, no .dts).
  • Only PCM stereo downmix supported (no multichannel, no passthrough).
  • You may still get an initial "This video does not support audio" message on first play of a .mkv with a DTS track, in which case you should just stop playback and try again (not too sure what can be done to get rid of this one)
  • The libraries and scripts have been designed for LG OLED CX models.
    While there is a good chance that, if your TV is not too dissimilar to OLED CXs, you might also be able to restore DTS support there, any issue that arises from not running this software on an OLED CX will be entirely yours to troubleshoot and support.

Further information

See https://github.com/lgstreamer/dts_restore.

Oh and moving it to its own GitHub repository allows to get some nice Download stats (see above).

pbatard avatar Jan 03 '23 00:01 pbatard

@pbatard great job! FYI v3 confirmed working for C1 (2021), C2 (2022), UN7400 (2020), NANO796 (2020)

aabytt avatar Jan 03 '23 08:01 aabytt

And here we go, as a new year's present, here's a working permanent DTS restoration package for LG OLED CX.

As LG promised, they finally released the sources for GStreamer (as part of the webOS 5.0 JO_2.0_1.tar.gz archive available here, which, as I suspected, allowed me to recompile a version of libgstmatroska.so that supports 2x playback.

The nice surprise, which I wasn't really expecting, is that 2x playback also works for DTS (as long as you don't play 4k videos, but that's a global limitation that applies to AC3/AAC too).

With this sorted out, I can therefore enable a more permanent means of restoring DTS support, since there shouldn't be any loss of functionality for non DTS media.

Download

Download Stats

You can download the new archive from HERE and basically the new DTS restore process is as simple as:

  • Open a root shell to your TV (e.g. using ssh)*
  • Download, extract and run the installer by issuing:
    cd /home/root
    wget https://github.com/lgstreamer/dts_restore/releases/download/1.0/dts_restore_1.0.tgz
    tar -xzvf dts_restore_1.0.tgz
    ./dts_install.sh
    

That's it.

An uninstaller (dts_uninstall.sh) is also provided if needed, but all it does, really, since it's all that's needed, is delete the /var/lib/webosbrew/init.d/restore_dts that was created by the installer.

Oh, and this new version does not alter any of the original firmware files, such as the GStreamer registry (which we regenerate in /tmp/ on each boot and use an overlay for) and minimises RAM usage by not duplicating unnecessary content to /tmp/.

Sources

I have now moved all the sources that were used to create the content under https://github.com/orgs/lgstreamer/repositories. Especially, you will find complete details on how you can recompile your own libgstmatroska.so as well as libgstlibav.so from the sources that were released by LG.

I'm still not completely sure why, since we're using the same source and should also be using the same configure options, our libgstlibav.so is so much bigger than LG's, but I suspect this has to do with being able to locate the shared ffmpeg library in our sysroot (using LG's sysroot was too much of a hassle), and, outside of the extra space taken, I don't really see much of an issue arising from this. Plus, in case LG also nerfed their ffmpeg, this should keep us safe from surprises...

Limitations (besides root)

  • Only mkv playback supported (no .mp4, no .dts).
  • Only PCM stereo downmix supported (no multichannel, no passthrough).
  • You may still get an initial "This video does not support audio" message on first play of a .mkv with a DTS track, in which case you should just stop playback and try again (not too sure what can be done to get rid of this one)
  • The libraries and scripts have been designed for LG OLED CX models. While there is a good chance that, if your TV is not too dissimilar to OLED CXs, you might also be able to restore DTS support there, any issue that arises from not running this software on an OLED CX will be entirely yours to troubleshoot and support.

Further information

See https://github.com/lgstreamer/dts_restore.

Oh and moving it to its own GitHub repository allows to get some nice Download stats (see above).

Thanks @pbatard! I can confirm that it's working on my tv too, the 43NANO766QA 2022 model. I have the "This video does not support audio" message but afer stop and replay the file, it works well. I opened a root shell using telnet, because when using ssh a "wget: error getting response: Connection reset by peer" message appears, but all commands passed successfully using telnet.

davix004 avatar Jan 18 '23 11:01 davix004

• Only PCM stereo downmix

why is that? isn't it possible to have 5+1?

P.S. @pbatard great work, I also have the CX, great TV! What firmware are you on at the moment?

Zibri avatar Jan 18 '23 11:01 Zibri

why is that?

Because the default gstreamer output device (audio sink) that is being used when not decoding audio using the closed source proprietary libraries (that call the hardware directly) only outputs stereo.

In short, that device says it accepts multichannel, but LG nerfed it so that only front left and front right are being output and everything else is discarded. And I have not discovered any "trick" to somehow toggle multichannel for that device. As a matter of fact, even when using the vanilla LG player and libraries, multichannel FLAC is not being handled properly and suffers the same issue of only FL + FR being output, because it seems FLAC is also being sent to the default limited gstreamer audio output sink.

I sure wish LG had bothered giving us a default audio device that handles multichannel and passthrough, as one would find on any regular Linux distro, but I suspect they designed the default audio output for apps audio output where only stereo was needed (note that movie playback from apps is still being handled by the video playback stack, so it's not limited by this), and they cut corners in terms of the development time they'd have to invest otherwise.

isn't it possible to have 5+1?

As I believe I explained above, there are 3 possible ways we may be able to get 5.1/7.1 which basically are:

  1. Spend an awful lot of time reverse engineering the existing closed source proprietary that handle audio decoding, and try to figure out a way to patch them for DTS output (since there seems to be hardware DTS decoding calls further down). Again, I have to stress out for anybody who believes that reverse engineering and patching existing binaries is easy that this is probably at least a 1 month FULL TIME job (i.e. 10 hours a day doing nothing else) without any clue as to whether there will be a massive roadblock that prevents the whole thing (such as the hardware calls having been left in in some libraries, but the hardware decoder having been removed altogether — Oh, and these hardware calls may be super specific to one model only, meaning you may only be able to satisfy CX owners and nobody else). In short, the cost/benefit ratio, if it's to help a handful owners, is just too high to be worth exploring.
  2. Spend a lot of time looking at the pulse audio and gstreamer audio output sink source, for which we should have most of the sources, to see if we could sort out a multichannel version. Now, because the audio output sink obviously needs to make hardware calls at some point, and we obviously don't have the technical specs from LG on how their proprietary audio hardware works, there too a lot of reverse engineering is expected to be needed, with potentially the same caveats as we have above, with whatever we do applying only to a specific model and nothing else.
  3. Spend some time crafting a gstreamer plugin that does DTS -> PCM conversion (e.g. BD PCM), so that the gstreamer native playback chain (which should be smart enough to do this automatically) will send the multichannel PCM output to LG's proprietary audio decoder library, and therefore to a working multichannel audio output. Obviously you won't get passthrough, whereas you may be able to get it with the other methods, but since it boils down to writing a standard gstreamer plugin, without having to reverse engineer or know anything about the underlying hardware, this is clearly the most attractive approach, since, unlike the other ones, one can estimate its difficulty and therefore the time it's likely to take, and it's also something you can develop without access to the hardware (since that plugin can apply to any Linux system that has gstreamer installed, and not just one with LG hardware). As far as I can tell, since we do have DTS decoding and PCM encoding from the gstreamer libav plugin, what's needed is to write a gstreamer manager plugin, that places the DTS decoding to multichannel PCM encoding into a black box that can then be presented as a DTS → multichannel PCM plugin. Of course, unless you're an experienced gstreamer developer (which I am not — I am still discovering the whole thing), whereas this looks relatively straightforward on paper, actually going through coding such a plugin is likely to be a lot more work and therefore require a lot more time, than people expect.

In short, considering that I'm planning to tackle approach 3, I'm hoping that, if I'm lucky, crafting such a plugin may only take me 1 week full time work (and will work, which is still not guaranteed), but as you can imagine, I can't exactly be taking 1 full week away from other activities just like this, so it'll probably be a month or two at best before I can spend enough time on looking into that. And that's hoping that this whole writing a gstreamer manager plugin doesn't turn out to be much more complex than I anaticipate... which, as with any software project, is almost always invariably the case.

Now of course, if someone wants to spend their own time looking at the pulse audio and gstreamer source to investigate approach 2, or even more time reverse engineering LG's proprietary libraries to poke 1, feel free to go ahead!

What firmware are you on at the moment?

As mentioned here (since this is what I used to root my TV) I'm on 04.40.20.

pbatard avatar Jan 18 '23 13:01 pbatard

I don't know if it helps somewhat but for some reason my LG CX could play DTS audio (with full 7.1 audio) through PLEX native app and via Direct Play too. But it only happens for one movie and it's Pan's Labyrinth (2006), with original Spanish language. I'm sorry if it's against the rule but I torrented it and the file name is Pans.Labyrinth.2006.SPANISH.2160p.BluRay.x265.10bit.HDR.DTS-HD.MA.7.1-SWTYBLZ.

So far I only notice that movie. All the other movies with DTS are always mute when playing dts via PLEX, except that one. Maybe because it is in Spanish and somehow LG lets it pass through? I'm just a casual viewer so maybe you can check it out to see if there's any trick you could discover.

furiseto avatar Jan 19 '23 05:01 furiseto

Pans.Labyrinth.2006.SPANISH.2160p.BluRay.x265.10bit.HDR.DTS-HD.MA.7.1-SWTYBLZ

Have you confirmed that the audio in that file is actually DTS?

throwaway96 avatar Jan 19 '23 07:01 throwaway96

Have you confirmed that the audio in that file is actually DTS?

Or the the PLEX application isn't doing transcoding on the fly, which, AFAIK, is what PLEX server does (i.e. it queries the target device to find out what kind of multichannel audio it can output and, if needed, such as if a device cannot output DTS, transcodes DTS to PCM or EAC when sending it to the device).

The DTS decoding on CX models is pretty black and white, and LG's explicitly removed DTS demuxing from the Matroska (mkv) gstreamer plugin, so there's absolutely no way you can get DTS playback with the vanilla gstreamer plugins when playing a .mkv (which your file appears to be), even if you actually have plugins and libraries further downstream that can decode DTS.

All the other movies with DTS are always mute when playing dts via PLEX, except that one.

My guess is that this movie has an additional EAC3/DD track besides the DTS one, and your other movies don't. The LG player is designed to automatically fall back to an audio track it can play if the first audio track it tries is not supported, and the behaviour you observe with some movies (with only a single DTS track) being silent while others (with a DTS track and an EAC3 track) producing audio is exactly what one would expect.

pbatard avatar Jan 19 '23 07:01 pbatard

Pans.Labyrinth.2006.SPANISH.2160p.BluRay.x265.10bit.HDR.DTS-HD.MA.7.1-SWTYBLZ

Have you confirmed that the audio in that file is actually DTS?

Yup, I checked and confirmed it's indeed DTS-MA. I also tried to play it through MPC-HC (PC) and it's mute with the "Audio Not Supported" message. But through PLEX it can play all 7.1 channels.

My guess is that this movie has an additional EAC3/DD track besides the DTS one, and your other movies don't. The LG player is designed to automatically fall back to an audio track it can play if the first audio track it tries is not supported, and the behaviour you observe with some movies (with only a single DTS track) being silent while others (with a DTS track and an EAC3 track) producing audio is exactly what one would expect.

The others are also bluray movies and they also have multi-tracks with DTS and EAC3 just like this one. And they can only play audio when I choose EAC3, no sound from DTS. That is why I was confused as heck and wonder why this specific movie, or rather, this specific file, is allowed to pass through DTS

Also here is a vid showing Plex's info screen I just recorded: https://youtu.be/9awka3CrlGs

P/s: In case anyone wondering, the soundbar you see in this vid is Samsung Q950A that supports all the sound codec and also eARC supported. The setting for the TV and soundbar is Pass-through and all HDMI bitstream.

furiseto avatar Jan 19 '23 09:01 furiseto

the soundbar you see in this vid is Samsung Q950A that supports all the sound codec

Hold on. What happens without the sound bar?

Pass through is a very different beast, so I could see how a track that is wrongly advertised as EAC3 but is actually DTS could end up being passed through by the PLEX app (though I have to say, this is one of the avenue I explored with the internal player as well, i.e. modify the gstreamer demuxer to set the audio type of the DTS data to x-audio/eac3 instead of x-audio/dts, but that didn't work for the LG gstreamer player). So it would be interesting to know if you still get sound output without the sound bar. And I'd be really interested to know what your soundbar see the audio as (if you had an amp, that info would usually be displayed on the front panel, but for a sound bar, I'm not sure if you can get it).

I guess if it turns out that a PLEX player that misreports DTS tracks as EAC can get the TV to just pass through the data, then we might as well try to build a PLEX app that always forces DTS as EAC always, as this should solve the multichannel output for people who have an external DTS decoding device.

pbatard avatar Jan 19 '23 10:01 pbatard

Hold on. What happens without the sound bar?

I just checked. Without the soundbar, and with Internal TV Speaker, the DTS audio still comes out just fine. The Plex Info still shows that it was streaming dca and 7.1.

And I'd be really interested to know what your soundbar see the audio as (if you had an amp, that info would usually be displayed on the front panel, but for a sound bar, I'm not sure if you can get it).

Yeah, unfortunately it doesn't show me what codec it is receiving. The soundbar's display only shows Dolby Atmos text whenever it detects one.

edit: remove link of the file

furiseto avatar Jan 19 '23 11:01 furiseto

Please don't post links to copyrighted content, even obfuscated. I would gather that if someone really wants to get their hands on the file you mention, they can do so without needing any other hints but the file name.

pbatard avatar Jan 19 '23 11:01 pbatard

Got it. Thanks for telling me.

furiseto avatar Jan 19 '23 11:01 furiseto

As far as I know plex server transcodes DTS but just leaves original label in app. @furiseto if you are rooted connect with ssh/telnet and run ls-monitor -f com.webos.media then launch a movie in plex and check the logs for sourceInfo event. It will show the tracks with the actual decoder info Looks like this:

{"sourceInfo":{"numPrograms":1,"container":"mkv","seekable":true,"trickable":true,"programInfo":[{"duration":1295552,"numAudioTracks":4,"audioTrackInfo":[{"bitRate":0,"language":"ru","codec":"ac3","sampleRate":48,"channels":2,"audioType":0},{"bitRate":0,"language":"ru","codec":"ac3","sampleRate":48,"channels":2,"audioType":0},{"bitRate":0,"language":"ru","codec":"ac3","sampleRate":48,"channels":2,"audioType":0},{"bitRate":0,"language":"en","codec":"ac3","sampleRate":48,"channels":6,"audioType":0} ],"numVideoTracks":1,"videoTrackInfo":[{"angleNumber":0,"level":3.1,"width":1280,"height":720,"codec":"H264","profile":"high","frameRate":23.976,"progressive":true} ],"numSubtitleTracks":2,"subtitleTrackInfo":[{"language":"ru","type":"text"},{"language":"en","type":"text"} ]} ],"mediaId":"_MQUBT01X5MiTj4"}}

aabytt avatar Jan 19 '23 12:01 aabytt

As far as I know plex server transcodes DTS but just leaves original label in app. @furiseto if you are rooted connect with ssh/telnet and run ls-monitor -f com.webos.media then launch a movie in plex and check the logs for sourceInfo event. It will show the tracks with the actual decoder info Looks like this:

{"sourceInfo":{"numPrograms":1,"container":"mkv","seekable":true,"trickable":true,"programInfo":[{"duration":1295552,"numAudioTracks":4,"audioTrackInfo":[{"bitRate":0,"language":"ru","codec":"ac3","sampleRate":48,"channels":2,"audioType":0},{"bitRate":0,"language":"ru","codec":"ac3","sampleRate":48,"channels":2,"audioType":0},{"bitRate":0,"language":"ru","codec":"ac3","sampleRate":48,"channels":2,"audioType":0},{"bitRate":0,"language":"en","codec":"ac3","sampleRate":48,"channels":6,"audioType":0} ],"numVideoTracks":1,"videoTrackInfo":[{"angleNumber":0,"level":3.1,"width":1280,"height":720,"codec":"H264","profile":"high","frameRate":23.976,"progressive":true} ],"numSubtitleTracks":2,"subtitleTrackInfo":[{"language":"ru","type":"text"},{"language":"en","type":"text"} ]} ],"mediaId":"_MQUBT01X5MiTj4"}}

I'm pretty amateur so my CX isn't rooted yet. So far I only used the Dev-manager method to install Homebrew and Youtube-adfree. Will try to look into alternate rooting method. If success then I will do what you said and post result.

But I'm actually confident that there isn't any transcoding process happening. Mainly because my plex server is my PC so I can easily check how much Plex's using resources from my i5 Gen10 cpu. And the absence of loading time also proves it is truly in Direct Play mode.

Still I'm gonna try to root my CX for further info.

furiseto avatar Jan 19 '23 13:01 furiseto

I'm actually confident that there isn't any transcoding process happening

Transcoding audio is peanuts. It's transcoding video that is CPU intensive, but for any modern processor, decoding and reencoding DTS to PCM will hardly make a dent in your resource usage.

my plex server is my PC

Then, as far as I know (though I am not that familiar with Plex), there is definitely automatic transcoding happening according to what the client device says it can handle. That's how Plex servers and clients are designed to work.

pbatard avatar Jan 19 '23 13:01 pbatard

I'm pretty amateur so my CX isn't rooted yet.

ok, no problem. I've installed plex and checked with my CX on the same video file as you did. When playing with plex client it shows DTS label (as originially track is) but actually server decodes it into AAC on the fly.

"audioTrackInfo":[{"bitRate":0,"language":"es","codec":"aac","profile":"lc","level":4,"sampleRate":48,"channels":6,"pid":257,"ctag":-1,"audioType":0,"trackId":-1,"immersive":"none","periodStart":0}]

transcoding happening according to what the client device says it can handle

Actually seems Plex is not so smart :) I’ve looked thru client options, there you can manually tick if your device supports DTS otherwise it will be always transcoded.

aabytt avatar Jan 19 '23 18:01 aabytt

After many attempts, I can finally root my CX and managed to pull the info:

"audioTrackInfo":[{"bitRate":0,"language":"es","codec":"ac3","sampleRate":48,"channels":6,"pid":-1,"ctag":-1,"audioType":0,"trackId":-1,"immersive":"none","periodStart":0}]

With Aabytt it's aac but with mine it's ac3.

I’ve looked thru client options, there you can manually tick if your device supports DTS otherwise it will be always transcoded.

yes, and I ticked it to DTS support. Plex leaves all the other movies with DTS audio alone, but somehow "secret transcode" Pan's Labyrinth into aac/ac3? Either CX misread the codec or it's just my failed hope all along...

I'm looking for a way to check whether Plex transcodes stuff or not in the Client's side, but I guess now I'm not much enthusiasm like before.

furiseto avatar Jan 26 '23 04:01 furiseto

With Aabytt it's aac but with mine it's ac3.

This file has 2 tracks. One is DTS and other is AC3. Plex streams only single selected track. I guess in your case you have AC3 selected and it is just streamed with no transcoding. If you switch to DTS track it will transcode it and you'll see AAC in audioTrackInfo

aabytt avatar Jan 26 '23 11:01 aabytt

@pbatard Thank you for the time you took to research how they removed the codecs!

Wouldn't it be easier to get the relevant files from a B9/C9 and replace them into the BX/CX to allow full functionality? (I mean splitter, decoder, surround and passthrough). After all, both TVs work almost the same.

alvgalrus avatar Jan 29 '23 12:01 alvgalrus