Ssh

X11轉發,如何強制音頻到主機?

  • May 20, 2021

我從筆記型電腦連接:

$ uname -a
Linux fedora 5.11.18-200.fc33.x86_64 #1 SMP Mon May 3 15:05:29 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

到單板電腦:

$ uname -a
Linux mobian 5.10-sunxi64 #2 SMP PREEMPT Tue Jan 12 09:55:56 UTC 2021 aarch64 GNU/Linux

通過帶有壓縮 X11 轉發的 SSH:

ssh -YC user@mobian

除了音頻在筆記型電腦中播放並且我希望它在遠端機器中播放之外,一切看起來都很棒。這是如何實現的?


PS我懷疑這是fedora特有的,因為ssh -YC user@mobian來自不同設備的相同連接:

$ uname -a
Linux sxmo 5.11.0 #1-postmarketos-allwinner SMP Sat Mar 27 14:48:00 UTC 2021 aarch64 GNU/Linux

將音頻輸出留在遠端機器上。


根據評論編輯:

Fedora 本地:

[user@fedora ~]$ xprop -root | grep PULSE
PULSE_COOKIE(STRING) = "28d747cacea4736118f778c450628a4b88489d1158cc10899f3bc54a078fe37b843810ebeb397abece2533b0d988569f3d01b838b2f7fa560712c78cc9d64cbba2d0e9e34f602b348ccf589d4f0bf159c9a078bf1a6e9a8140f930b2d5e4cb21cb31bf8f22112b2cfd2476f02694e3060ae9f3918e58629a49ec1fbb730c2af4dee1f42de13c0046b2f7fc664302724fbc3d27a0863e98dcede752d9451644d6f8b5e10f0a1ec88320b8686b292b6225c02c043719818a4d4041fcb60bfeef97ebfb6601f83c5d8052a64489c5507ac02876d171a6bb942f20991e0a31271c97d2ba3b9f8baef66a06affb5d33aa198be394f798622d6ffd8d2a5926a8402a08"
PULSE_SERVER(STRING) = "{f5e96850fbf948e19c0eba4f100fa72a}unix:/run/user/1000/pulse/native tcp:fedora.localdomain:4713 tcp6:fedora.localdomain:4713"
PULSE_SESSION_ID(STRING) = "2"
PULSE_ID(STRING) = "1000@f5e96850fbf948e19c0eba4f100fa72a/1985"

遠端在 mobian 上沒有-YC

user@mobian:~$ xprop -root | grep PULSE
xprop:  unable to open display ''

在 mobian 上遠端使用-YC

[user@fedora ~]$ ssh user@mobian -YC

...

user@mobian:~$ xprop -root | grep PULSE
PULSE_COOKIE(STRING) = "28d747cacea4736118f778c450628a4b88489d1158cc10899f3bc54a078fe37b843810ebeb397abece2533b0d988569f3d01b838b2f7fa560712c78cc9d64cbba2d0e9e34f602b348ccf589d4f0bf159c9a078bf1a6e9a8140f930b2d5e4cb21cb31bf8f22112b2cfd2476f02694e3060ae9f3918e58629a49ec1fbb730c2af4dee1f42de13c0046b2f7fc664302724fbc3d27a0863e98dcede752d9451644d6f8b5e10f0a1ec88320b8686b292b6225c02c043719818a4d4041fcb60bfeef97ebfb6601f83c5d8052a64489c5507ac02876d171a6bb942f20991e0a31271c97d2ba3b9f8baef66a06affb5d33aa198be394f798622d6ffd8d2a5926a8402a08"
PULSE_SERVER(STRING) = "{f5e96850fbf948e19c0eba4f100fa72a}unix:/run/user/1000/pulse/native tcp:fedora.localdomain:4713 tcp6:fedora.localdomain:4713"
PULSE_SESSION_ID(STRING) = "2"
PULSE_ID(STRING) = "1000@f5e96850fbf948e19c0eba4f100fa72a/1985"

mobian本地:

user@mobian:~$ xprop -root | grep PULSE
PULSE_COOKIE(STRING) = "8139d0fdc04752954ff9018ca4006d741d1b8aef9ed8fdd041184fda6080bad0fbf0e0ca00ecc6eacd5b4adde99d84ac33932773da3b8dd99a2adaeb085cd622daefbd75ab193690185f856457ac9541a1e4075a8217484df1bd136d00bc6c0c80abef6e3ee86daed144c33fece49cd9a896c3bb7dcb6520441f21c48a7f045693d9d6e47e2f7bc32ce6ce4b958df2842f8d7298d690e48a1343fbed5310fa50475acaf928047802978cf0f417502c298332b56e5a66a75b97e9ddb59a739e4d34c8f63fbb7ce883b35ed115c44639db11d5e543665978dfcbe43b5d8d41677ee68195c153103986283d80b2ce3239559f12d2928b9ffb05054e3cca70ff277d"
PULSE_SERVER(STRING) = "{e5ca38bfe5be445f838be0328a1c5f33}unix:/run/user/1000/pulse/native tcp:mobian.localdomain:4713 tcp6:mobian.localdomain:4713"
PULSE_ID(STRING) = "1000@e5ca38bfe5be445f838be0328a1c5f33/615"

似乎解決方案在這裡描述:

https ://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Network/#xforwarding

這都是關於PULSE_SERVER“變數”的。因此,使用 appenden before 啟動程序PULSE_SERVER=localhost可確保音頻協議在主機上執行。在我的情況下,單板電腦而不是筆記型電腦。

我只有一次機會對此進行測試,所以我不確定它是否適用於所有場景,但它是:

[user@fedora ~]$ ssh user@mobian -YC

...


user@mobian:~$ PULSE_SERVER=localhost [YOUR_APLICATION]

如果我得到更多資訊,我會嘗試更新。

引用自:https://unix.stackexchange.com/questions/649950