Skip to content

Commit e76ca5c

Browse files
Release v1.1.6 — conditional 5.1 webOS channel remap
Only remap Opus 5.1 to NDL order when the host did not already send webOS layout via surround_params, fixing Apollo regressions from #50. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 8c0c62e commit e76ca5c

2 files changed

Lines changed: 37 additions & 16 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.19)
22
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
33

4-
set(MOONLIGHT_VERSION "1.1.5")
4+
set(MOONLIGHT_VERSION "1.1.6")
55

66
project(moonlight VERSION ${MOONLIGHT_VERSION} LANGUAGES C CXX)
77

src/app/stream/audio/session_audio.c

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <stdlib.h>
2+
#include <string.h>
23
#include <assert.h>
34

45
#include <opus_multistream.h>
@@ -18,7 +19,38 @@ static int frame_size = 0, unit_size = 0;
1819

1920
AUDIO_INFO audio_stream_info;
2021

21-
static size_t opus_head_serialize(const OPUS_MULTISTREAM_CONFIGURATION *config, unsigned char *data);
22+
static size_t opus_head_serialize(const POPUS_MULTISTREAM_CONFIGURATION *config, unsigned char *data);
23+
24+
#if TARGET_WEBOS
25+
/* NDL/webOS Opus 5.1 layout (FL FR RL RR C LFE). Same as surround_params "642014523". */
26+
static const unsigned char WEBOS_OPUS_51_MAPPING[6] = {0, 1, 4, 5, 2, 3};
27+
28+
static void maybe_remap_webos_51(OPUS_MULTISTREAM_CONFIGURATION *config) {
29+
if (config->channelCount != 6) {
30+
return;
31+
}
32+
/* Hosts that honor surround_params already send webOS order — remapping again
33+
* swaps channels (regression for Apollo on some sets after #50). Only remap when
34+
* the stream is still in Moonlight/SDL order (FL FR C LFE RL RR). */
35+
if (memcmp(config->mapping, WEBOS_OPUS_51_MAPPING, sizeof(WEBOS_OPUS_51_MAPPING)) == 0) {
36+
commons_log_info("Session", "5.1 Opus mapping already webOS order; skip remap");
37+
return;
38+
}
39+
40+
unsigned char tmp;
41+
/* Center (2) <-> Surround Left (4); LFE (3) <-> Surround Right (5) */
42+
tmp = config->mapping[2];
43+
config->mapping[2] = config->mapping[4];
44+
config->mapping[4] = tmp;
45+
tmp = config->mapping[3];
46+
config->mapping[3] = config->mapping[5];
47+
config->mapping[5] = tmp;
48+
commons_log_info("Session",
49+
"5.1 Opus mapping remapped to webOS order [%u,%u,%u,%u,%u,%u]",
50+
config->mapping[0], config->mapping[1], config->mapping[2],
51+
config->mapping[3], config->mapping[4], config->mapping[5]);
52+
}
53+
#endif
2254

2355
static int aud_init(int audioConfiguration, const POPUS_MULTISTREAM_CONFIGURATION opusConfig, void *context,
2456
int arFlags) {
@@ -32,20 +64,9 @@ static int aud_init(int audioConfiguration, const POPUS_MULTISTREAM_CONFIGURATIO
3264

3365
OPUS_MULTISTREAM_CONFIGURATION config_copy = *opusConfig;
3466

35-
// Swap channels for 5.1 surround sound because the Moonlight library normalizes to
36-
// FL, FR, Center, LFE, RL, RR but WebOS hardware expects FL, FR, RL, RR, Center, LFE.
37-
if (config_copy.channelCount == 6) {
38-
unsigned char tmp;
39-
// Swap Front Center (2) <-> Rear/Surround Left (4)
40-
tmp = config_copy.mapping[2];
41-
config_copy.mapping[2] = config_copy.mapping[4];
42-
config_copy.mapping[4] = tmp;
43-
44-
// Swap Subwoofer/LFE (3) <-> Rear/Surround Right (5)
45-
tmp = config_copy.mapping[3];
46-
config_copy.mapping[3] = config_copy.mapping[5];
47-
config_copy.mapping[5] = tmp;
48-
}
67+
#if TARGET_WEBOS
68+
maybe_remap_webos_51(&config_copy);
69+
#endif
4970

5071
SS4S_AudioInfo info = {
5172
.numOfChannels = config_copy.channelCount,

0 commit comments

Comments
 (0)