Serve the renderer's channel order without touching the player's layout

This commit is contained in:
TheM14 committed 2026-10-29 01:09:55 +08:00
1 parent 95c4626abd
commit 78f2c4b4bd
13 files changed
+146 -114

No files matched your search

+1 -2
View File
@@ -395,10 +395,9 @@ struct Plugin {
auto created = std::make_shared<Stream>();
created->source = source;
const std::string mask_layout = (config.output == 0) ? "2.0" : config.layout;
created->header = joc_mpv::wav_header(
source->channels(), source->bits_per_sample(),
joc_mpv::channel_mask(mask_layout, source->channels()), source->data_bytes());
joc_mpv::channel_mask(source->channels()), source->data_bytes());
created->total_bytes = created->header.size() + source->data_bytes();
const double per_write = config.chunk_seconds * 48000.0 *
static_cast<double>(source->bytes_per_frame());
+22 -15
View File
@@ -354,14 +354,26 @@ private:
HANDLE handle_ = INVALID_HANDLE_VALUE;
};
// The layouts the core accepts, with their channel counts. "4.0" is the old
// spelling of 4.0 Surround and is resolved to it before the core is asked, but the
// count table keeps it too so an old configuration still logs its real width.
const char* const kLayouts[] = {"2.0", "3.1",
"4.0 Surround", "4.0 Quad", "4.0",
"5.1", "7.1", "5.1.2", "5.1.4",
"7.1.2", "7.1.4", "9.1.4", "9.1.6"};
const unsigned kLayoutChannels[] = {2, 4, 4, 4, 4, 6, 8, 8, 10, 10, 12, 14, 16};
// The layouts the core accepts, with their channel counts. The counts have to
// stay in step with the core's table.
struct LayoutEntry {
const char* name;
unsigned channels;
};
const LayoutEntry kLayouts[] = {
{"2.0", 2},
{"3.1", 4},
{"4.0", 4},
{"5.1", 6},
{"7.1", 8},
{"5.1.2", 8},
{"5.1.4", 10},
{"7.1.2", 10},
{"7.1.4", 12},
{"9.1.4", 14},
{"9.1.6", 16},
};
// Every ffmpeg child writes its diagnostics next to the component rather than into
// whatever working directory the host process happens to have; separate files so
@@ -410,14 +422,9 @@ std::int64_t sample_of_seconds(double seconds) {
} // namespace
const char* const* speaker_layouts(std::size_t* count) {
if (count != nullptr) *count = sizeof(kLayouts) / sizeof(kLayouts[0]);
return kLayouts;
}
unsigned speaker_channels(const std::string& layout) {
for (std::size_t i = 0; i < sizeof(kLayouts) / sizeof(kLayouts[0]); ++i) {
if (layout == kLayouts[i]) return kLayoutChannels[i];
for (const LayoutEntry& entry : kLayouts) {
if (layout == entry.name) return entry.channels;
}
return 0;
}
-3
View File
@@ -120,9 +120,6 @@ std::string component_directory();
// component directory cannot be determined.
std::string resolve_hrtf_file(const Settings& settings);
// Every layout the core accepts, in the order a settings page should list them.
const char* const* speaker_layouts(std::size_t* count);
// Result of examining a file without rendering anything.
struct FileProbe {
bool readable = false;
+4 -16
View File
@@ -29,28 +29,16 @@ bool truthy(const std::string& value) {
}
// The layout names the renderer accepts, in the order its reference lists them.
const char* const kLayouts[] = {"2.0", "3.1", "4.0 Surround", "4.0 Quad",
"5.1", "7.1", "5.1.2", "5.1.4",
"7.1.2", "7.1.4", "9.1.4", "9.1.6"};
// "4.0" is the spelling the option had before the two 4.0 layouts were told
// apart; it has always meant the layout now called 4.0 Surround.
std::string canonical_layout(const std::string& layout) {
return layout == "4.0" ? "4.0 Surround" : layout;
}
const char* const kLayouts[] = {"2.0", "3.1", "4.0", "5.1", "7.1", "5.1.2",
"5.1.4", "7.1.2", "7.1.4", "9.1.4", "9.1.6"};
} // namespace
const char* layout_list() {
return "2.0, 3.1, 4.0 Surround, 4.0 Quad, 5.1, 7.1, 5.1.2, 5.1.4, 7.1.2, 7.1.4, "
"9.1.4, 9.1.6";
}
bool valid_layout(const std::string& layout) {
for (const char* name : kLayouts) {
if (layout == name) return true;
}
return layout == "4.0";
return false;
}
Config parse_config(const std::string& script_opts, std::string* warnings) {
@@ -91,7 +79,7 @@ Config parse_config(const std::string& script_opts, std::string* warnings) {
}
} else if (key == "joc-layout") {
if (valid_layout(value)) {
config.layout = canonical_layout(value);
config.layout = value;
} else {
unsupported(key + "=" + value);
}
-1
View File
@@ -50,7 +50,6 @@ struct Config {
// keys are ignored so an mpv.conf written for a newer build still loads.
Config parse_config(const std::string& script_opts, std::string* warnings);
const char* layout_list();
bool valid_layout(const std::string& layout);
} // namespace joc_mpv
+4 -34
View File
@@ -7,17 +7,6 @@ namespace {
constexpr std::uint32_t kFl = 0x00000001u;
constexpr std::uint32_t kFr = 0x00000002u;
constexpr std::uint32_t kFc = 0x00000004u;
constexpr std::uint32_t kLfe = 0x00000008u;
constexpr std::uint32_t kBl = 0x00000010u;
constexpr std::uint32_t kBr = 0x00000020u;
constexpr std::uint32_t kBc = 0x00000100u;
constexpr std::uint32_t kSl = 0x00000200u;
constexpr std::uint32_t kSr = 0x00000400u;
constexpr std::uint32_t kTfl = 0x00001000u;
constexpr std::uint32_t kTfr = 0x00004000u;
constexpr std::uint32_t kTbl = 0x00008000u;
constexpr std::uint32_t kTbr = 0x00020000u;
void put_u16(std::string* out, std::uint16_t value) {
char bytes[2];
@@ -65,29 +54,10 @@ void put_fmt(std::string* out, unsigned channels, unsigned bits, std::uint32_t m
} // namespace
std::uint32_t channel_mask(const std::string& layout, unsigned channels) {
if (layout == "2.0") return kFl | kFr;
if (layout == "3.1") return kFl | kFr | kFc | kLfe;
// The two 4.0 layouts differ in their speaker set, not only in their name:
// Surround has a front trio and one back-centre speaker, Quad has a front and
// a back pair and neither centre nor LFE. "4.0" is the old name of the former.
if (layout == "4.0 Surround" || layout == "4.0") return kFl | kFr | kFc | kBc;
if (layout == "4.0 Quad") return kFl | kFr | kBl | kBr;
if (layout == "5.1") return kFl | kFr | kFc | kLfe | kBl | kBr;
if (layout == "7.1") return kFl | kFr | kFc | kLfe | kBl | kBr | kSl | kSr;
if (layout == "5.1.2") return kFl | kFr | kFc | kLfe | kBl | kBr | kTfl | kTfr;
if (layout == "5.1.4") {
return kFl | kFr | kFc | kLfe | kBl | kBr | kTfl | kTfr | kTbl | kTbr;
}
if (layout == "7.1.2") {
return kFl | kFr | kFc | kLfe | kBl | kBr | kSl | kSr | kTfl | kTfr;
}
if (layout == "7.1.4") {
return kFl | kFr | kFc | kLfe | kBl | kBr | kSl | kSr | kTfl | kTfr | kTbl | kTbr;
}
// 2-channel binaural output is plain stereo.
if (channels == 2) return kFl | kFr;
return 0;
std::uint32_t channel_mask(unsigned channels) {
// No mask above stereo: the channel order is the renderer's, and a WAVE mask
// would claim a different one. Two channels are plain stereo.
return channels == 2 ? (kFl | kFr) : 0;
}
std::string wav_header(unsigned channels, unsigned bits_per_sample, std::uint32_t mask,
+4 -5
View File
@@ -5,11 +5,10 @@
namespace joc_mpv {
// Channel mask for a layout the renderer can produce. The renderer emits its
// channels in the standard WAVE order for that layout, so a WAVE_FORMAT_EXTENSIBLE
// mask tells mpv exactly which speaker each channel belongs to. Layouts wider
// than 7.1 return 0 (no mask): they cannot reach a WASAPI endpoint anyway.
std::uint32_t channel_mask(const std::string& layout, unsigned channels);
// Channel mask for the served WAV. The PCM follows the renderer's channel order,
// which no WAVE mask describes, so anything wider than stereo is declared with no
// speaker positions at all (mask 0). Two channels are FL/FR in either definition.
std::uint32_t channel_mask(unsigned channels);
// 68-byte WAVE_FORMAT_EXTENSIBLE header, or a 104-byte RF64 header when the data
// chunk would not fit a 32-bit size.