OneLiberty / moonlight-chrome-tizen

A WASM port of Moonlight for Samsung Smart TV's running Tizen OS (5.5 and up)
GNU General Public License v3.0
185 stars 15 forks source link

Audio output settings #40

Open fidoboy opened 4 months ago

fidoboy commented 4 months ago

When I was using the moonlight client for PC I was able to select audio output and I got 5.1 sound through my HDMI connect to the TV and the TV connected with optical cable to my sound system. But now with the Tizen client there is no setup options to select 5.1 sound and I'm only listening stereo sound (the sound system is displaying also that it's receiving a two channels stream). So my question is: Can this be added to this client? How can I get 5.1 sound from this Moonlight client?

henryfa2 commented 4 months ago

When I was using the moonlight client for PC I was able to select audio output and I got 5.1 sound through my HDMI connect to the TV and the TV connected with optical cable to my sound system. But now with the Tizen client there is no setup options to select 5.1 sound and I'm only listening stereo sound (the sound system is displaying also that it's receiving a two channels stream). So my question is: Can this be added to this client? How can I get 5.1 sound from this Moonlight client?

At the moment, the Tizen App is automatically set to Stereo, yes. It looks like it can be updated to handle 5.1 setup. That would require to update the connection string sent to the sunshine server + update the wasm player configuration. Thing is, since I do not have such setup, I can't test it if I develop it. :(

fidoboy commented 4 months ago

I can test it. Just sent me the modified version

fidoboy commented 4 months ago

Right now is working amazingly well but the only issue for not using it is the lack of 5.1 surround sound output. Other than this I've tried HDR and also 2K output and works fine even with a WIFI connection.

If you could add a experimental feature to select the sound channels output I can test it and I'll report back any issue.

henryfa2 commented 4 months ago

Right now is working amazingly well but the only issue for not using it is the lack of 5.1 surround sound output. Other than this I've tried HDR and also 2K output and works fine even with a WIFI connection.

If you could add a experimental feature to select the sound channels output I can test it and I'll report back any issue.

I'll take a look this week. Before I invest too much time doing something clean (aka not hardcoding anything), I can make a "dirty" version hardcoding everything to 5.1 so you can try and confirm it works. And later a clean version, if your test is OK, where user can select stereo or 5.1. Is that OK?

fidoboy commented 4 months ago

Right now is working amazingly well but the only issue for not using it is the lack of 5.1 surround sound output. Other than this I've tried HDR and also 2K output and works fine even with a WIFI connection. If you could add a experimental feature to select the sound channels output I can test it and I'll report back any issue.

I'll take a look this week. Before I invest too much time doing something clean (aka not hardcoding anything), I can make a "dirty" version hardcoding everything to 5.1 so you can try and confirm it works. And later a clean version, if your test is OK, where user can select stereo or 5.1. Is that OK?

Yes. That could be perfect. I can test it with no problem to verify if the output is 5.1 or not.

henryfa2 commented 4 months ago

Right now is working amazingly well but the only issue for not using it is the lack of 5.1 surround sound output. Other than this I've tried HDR and also 2K output and works fine even with a WIFI connection. If you could add a experimental feature to select the sound channels output I can test it and I'll report back any issue.

I'll take a look this week. Before I invest too much time doing something clean (aka not hardcoding anything), I can make a "dirty" version hardcoding everything to 5.1 so you can try and confirm it works. And later a clean version, if your test is OK, where user can select stereo or 5.1. Is that OK?

Yes. That could be perfect. I can test it with no problem to verify if the output is 5.1 or not.

Hello there, I've uploaded a version of the app with 5.1 support. From what I can see in the Sunshine logs, it is fine (5.1 audio output). Sadly, since my TV only got stereo, I can't check that sound is 5.1. The 5.1 support is here : https://github.com/henryfa2/moonlight-chrome-tizen/tree/samsung_wasn_dev_5-1_test_support Can you test and tell me if it is working? If yes, I'll see to implement it correctly (allow people to choose between 5.1 and stereo, instead of forcing 5.1).

fidoboy commented 4 months ago

Right now is working amazingly well but the only issue for not using it is the lack of 5.1 surround sound output. Other than this I've tried HDR and also 2K output and works fine even with a WIFI connection. If you could add a experimental feature to select the sound channels output I can test it and I'll report back any issue.

I'll take a look this week. Before I invest too much time doing something clean (aka not hardcoding anything), I can make a "dirty" version hardcoding everything to 5.1 so you can try and confirm it works. And later a clean version, if your test is OK, where user can select stereo or 5.1. Is that OK?

Yes. That could be perfect. I can test it with no problem to verify if the output is 5.1 or not.

Hello there, I've uploaded a version of the app with 5.1 support. From what I can see in the Sunshine logs, it is fine (5.1 audio output). Sadly, since my TV only got stereo, I can't check that sound is 5.1. The 5.1 support is here : https://github.com/henryfa2/moonlight-chrome-tizen/tree/samsung_wasn_dev_5-1_test_support Can you test and tell me if it is working? If yes, I'll see to implement it correctly (allow people to choose between 5.1 and stereo, instead of forcing 5.1).

I believe that you need to put your branch public to allow the docker run from a github registry (ghcr.io). I can't execute the docker run as it is right now

fidoboy commented 4 months ago

I've tried my best with:

docker build https://github.com/henryfa2/moonlight-chrome-tizen.git#samsung_wasn_dev_5-1_test_support

but I believe that the created WGT file is from the OneLiberty main branch (because the Docker file remains the same than in the original branch), so as a result, the app in my TV only outputs stereo sound as before. So please, make it public for the Github registry (ghcr.io) or tell me the right command to build the app from the source in Docker.

henryfa2 commented 4 months ago

You can download the zip, extract, open a cmd in the directory, then : docker build . -t moonlight-chrome-tizen_perso docker run --rm -it moonlight-chrome-tizen_perso sdb connect TV_IP tizen install -n MoonlightWasm.wgt -t DEVICE_ID

fidoboy commented 4 months ago

You can download the zip, extract, open a cmd in the directory, then : docker build . -t moonlight-chrome-tizen_perso docker run --rm -it moonlight-chrome-tizen_perso sdb connect TV_IP tizen install -n MoonlightWasm.wgt -t DEVICE_ID

Thanks a lot. I'll try it this way.

fidoboy commented 4 months ago

It doesn't work. Still stereo sound through my receiver. Using the Moonlight client connected to the same Sunshine PC host I get 5.1 sound without any problem

fidoboy commented 4 months ago

To do the test I opened a remote desktop connection with Moonlight and then, from the sound settings panel in Windows, I used the button "Configure" for the "Steam Streaming Speakers" where there is a 5.1 speakers scheme. With this I can click on each speaker to get a sound and check if it comes from the right speaker in my room. With the Tizen app, when I do that, the sound comes from the front speakers when I click on the rear speakers. So if I click on the left rear speaker the sound comes from the left front speaker, the same that when I click on the front left speaker. Also the Subwoofer speaker doesn't work and the sound comes from the small center speaker. So it's working in stereo mode, sending all the sound to the left or right channels only.

Doing this same test from the Moonlight Windows client, each sound comes from the right speaker and I verify that it works in 5.1 mode (also the Samsung TV display at top a Dolby symbol with the letters DTHD). From the Tizen app I don't know how to display the resolution, Hz and operation mode on screen with my TV remote controller. But there is only stereo sound anyway

henryfa2 commented 4 months ago

Can you upload a sunshine logs after you started a stream? Logs gotta be verbose (tab 'General' in Sunshine config panel)

fidoboy commented 4 months ago

Can you upload a sunshine logs after you started a stream? Logs gotta be verbose (tab 'General' in Sunshine config panel)

I've found this significative fragments into the log. Hope it helps:

[2024:04:20:11:33:54]: Verbose: Increasing FEC percentage to 200 to meet parity shard minimum [2024:04:20:11:33:54]: Verbose: Frame [21] :: send [3] shards... [2024:04:20:11:33:54]: Debug: Skipping audio format [Stereo] with channel count [2 != 6] [2024:04:20:11:33:54]: Debug: Trying audio format [Surround 5.1] [2024:04:20:11:33:54]: Verbose: type [IDX_ENCRYPTED] [2024:04:20:11:33:54]: Verbose: type [IDX_START_A] [2024:04:20:11:33:54]: Verbose: Recv: ::ffff:192.168.0.20:55958 :: AUDIO [2024:04:20:11:33:54]: Debug: Found audio format [Surround 5.1]

and also this:

[2024:04:20:11:33:51]: Debug: Expecting incoming session connections from ::ffff:192.168.0.20 [2024:04:20:11:33:51]: Verbose: Recv: ::ffff:192.168.0.20:55958 :: AUDIO [2024:04:20:11:33:51]: Debug: RAISE: ::ffff:192.168.0.20:55958 :: AUDIO [2024:04:20:11:33:51]: Debug: Received ping [v2] from ::ffff:192.168.0.20:55958 [0200000037344145374239424246394532304141] [2024:04:20:11:33:51]: Debug: Using qWAVE connect() workaround for QoS tagging [2024:04:20:11:33:51]: Warning: QOSAddSocketToFlow() failed: 1168 [2024:04:20:11:33:51]: Debug: Start capturing Audio [2024:04:20:11:33:51]: Debug: Stereo: supported [2024:04:20:11:33:52]: Debug: Surround 5.1: supported [2024:04:20:11:33:52]: Info: nvprefs: No need to modify application profile settings [2024:04:20:11:33:52]: Info: nvprefs: No need to modify global profile settings [2024:04:20:11:33:52]: Debug: Surround 7.1: supported [2024:04:20:11:33:52]: Debug: Stereo: supported [2024:04:20:11:33:52]: Debug: ---Begin Response--- RTSP/1.0 200 OK

CSeq: 6

---End Response---

NOTE: The IP 192.168.0.20 is the address of my Samsung TV

henryfa2 commented 4 months ago

Yeah so it seems the stream is set to 5.1 audio setup. Problem is probably the Tizen wasm player interpreting it as a stereo setup :/ I'll try to check the code again

henryfa2 commented 4 months ago

@fidoboy Does your 5.1 setup supports eARC? How is it connected to your tv? Edit : I ask this because from I read, Sunshine can only stream audio in PCM format. Dolby Digital, DTS, or Atmos are not supported. Since PCM is a format without compression, it seems you need some hardware able to handle that. Cf. this reddit post : https://www.reddit.com/r/LizardByte/comments/11918sa/comment/ja7wmv8/ NB : I tried changing the audio codec from PCM to AC3 in our Tizen Moonlight version and i had no audio as a result (which is logical if sunshine is streaming PCM format)

fidoboy commented 4 months ago

The sound system is connected to the TV using a optical cable. So the TV outputs the sound throught the optical wire. As you can see here: https://www.samsung.com/us/support/troubleshooting/TSG01109021/ 5.1 is supported from the TV apps. As I've metioned before, this same setup, using a miniPC connected to the same TV with HDMI, outputs 5.1 perfectly, with no issues. And, of course, also with same optical cable. However it doesn't work from the Tizen app with same configuration. I only get stereo sound. Only difference is from a Windows client to a Tizen client, both cases the Moonlight app.

The PC is connected to the TV only with HDMI cable. It's not connected to the sound system directly, so it's the TV that it's sending the sound from the HDMI encoded source to the optical. I can see when I activate the information layer on the TV that when using the Moonlight Windows client the DTHD letters for the sound are being displayed next to the HDR and HD symbols.

As example, I can also say that I also use the Tizen Plex app and others, and it outputs 5.1 sound in various formats through the optical cable without any hassle.

fidoboy commented 4 months ago

May be that the app also need to specify some kind of encoding or something like that and not only the number of channels. From the TV settings, into the sound config, I can only select between PCM or Automatic. I always keep it on Automatic and it always worked fine.

fidoboy commented 4 months ago

I'll try to make a scheme of the setup:

Both cases is the same Samsung TV and the same optical cable to output the sound.

henryfa2 commented 4 months ago

Well, I did some tests but couldn't get something working :/ I'm sorry

fidoboy commented 4 months ago

Well, I did some tests but couldn't get something working :/ I'm sorry

Thanks a lot anyway for the effort. To my understanding, if it works on Windows client then it should work the same way on the Tizen client because the source of the stream (Sunshine) is the same. So in both cases they are receiving the same sound stream with 5.1 sound channels. Also the wire to send the digital sound signal to the output is the same: the optical toslink connection.

AFAIK if the Tizen client has a setup to select the amount of sound channels may be the problem is with the Tizen SDK itself, into the libraries of this platform. I suppose that the Sunshine host server is sending RAW digital data without any encoding so it's the receiver the one that encodes to the output. In the Windows case it's doing it correctly because the TV is sending it encoded through the optical out. But in the case of Tizen app it seems that there is not a right approach and the sound decoder is not receiving the signal from the optical input encoded into a 5.1 format. So I think that this encoding process should be done by the Tizen platform and coded into the Moonlight app if it's possible to do it.

If it's working on Windows, there is something that the Moonlight client or the Windows libraries are doing well and that it's missing on the Tizen platform or the Tizen app. And I suspect that it's about the encoding. May be that it's the Dolby format because the DTHD symbol it's being displayed on the Samsung TV info overlay when I'm using the Windows client.

fidoboy commented 4 months ago

Well, I did some tests but couldn't get something working :/ I'm sorry

I've found this: https://github.com/jellyfin/jellyfin-tizen/issues/204 and it seems that it's possible to transcode the audio into AC3 or EAC3. So if the Moonlight client for Tizen could transcode to AC3 or EAC3 that has support for 5.1 surround sound instead of AAC that only supports stereo, problem is solved.

Can you make the changes into the code to select the AC3 format and then I can test it?

henryfa2 commented 4 months ago

Well, Samsung devs gave a bit of info about audio there : https://developer.samsung.com/smarttv/develop/extension-libraries/webassembly/game-streaming-on-tizen-tv-with-wasm.html :

In GameStreaming protocol audio data was transported in network packets as Opus frames. Some older Tizen TVs were however not able to decode Opus in hardware while using low-latency playback modes. Thus the audio has to be decoded using libopus to be passed further as a raw audio stream to the Tizen Wasm Player API

They transcoded the opus audio to a raw format audio (PCM) on purpose. I don't know how to transcode audio to another format (AC3).

fidoboy commented 3 months ago

The key would be for Sunshine to be able to use AC3 streams and not only PCM as it's right now. I can't understand why there is availability for image formats like HEVC, H264 and AV1 but there is not anyone for audio. AFAIK there shouldn't be so difficult to add audio encoding option on demand. This way if a Moonlight client request it (in Tizen or ChromeOS platforms, for example) there is no problem to do a passthrough for a optical toslink in only two compressed channels that the audio sound system could easy decode to 5.1 channels again. And if another client request the PCM stream it can be delivered the same as it is until now.

May be that we can make some pressure to the Sunshine team so they consider adding this as a new feature to expand the compatibility with many Smart TV devices. I've created a request here: https://ideas.moonlight-stream.org/posts/360/add-support-for-5-1-encoded-audio-stream just in case that anyone wants to support it giving a positive vote or adding comments with his thoughts or ideas about the issue.

Also I believe that today the Dolby Digital formats aren't protected with privative patents, so anyone can use it with projects like Sushine or Moonlight. That's why I can't honestly understand that there is no support for this already. The bandwidth could be also way too much smaller than when using the raw PCM stream.

elbolutony commented 2 weeks ago

Right now is working amazingly well but the only issue for not using it is the lack of 5.1 surround sound output. Other than this I've tried HDR and also 2K output and works fine even with a WIFI connection. If you could add a experimental feature to select the sound channels output I can test it and I'll report back any issue.

I'll take a look this week. Before I invest too much time doing something clean (aka not hardcoding anything), I can make a "dirty" version hardcoding everything to 5.1 so you can try and confirm it works. And later a clean version, if your test is OK, where user can select stereo or 5.1. Is that OK?

Yes. That could be perfect. I can test it with no problem to verify if the output is 5.1 or not.

Hello there, I've uploaded a version of the app with 5.1 support. From what I can see in the Sunshine logs, it is fine (5.1 audio output). Sadly, since my TV only got stereo, I can't check that sound is 5.1. The 5.1 support is here : https://github.com/henryfa2/moonlight-chrome-tizen/tree/samsung_wasn_dev_5-1_test_support Can you test and tell me if it is working? If yes, I'll see to implement it correctly (allow people to choose between 5.1 and stereo, instead of forcing 5.1).

Hi, i've tested this build (rather, build it myself): TV: QN90B Soundbar: Q700A through eARC. And the sound came garbled, like in another Sample Rate (i've tried changing 48khz 16/24bit), and... the channels were mixed, coming from the side speakers.

ailison commented 6 days ago

I am waiting on this one as well. :) I have a 9.2.1 system + the Q-Symphony configured.