Files
iptvnator/apps/electron-backend/native/src/embedded_mpv_extra_options.h
T
ZoultandClaude Fable 5.1 5a11b82eaf feat(embedded-mpv): configurable extra libmpv options and network auto-reconnect (#1515)
Extra libmpv options (Settings > Playback) reach every embedded engine off the command line (createSession array on Windows/macOS, a 0600 --include file on Linux native-view, a stdin preamble for the frame-copy helper); the keys the embed depends on are refused, and keys libmpv rejects are reported once per session. Dropped streams reload automatically (error, or ended on live) with 2 s -> 30 s backoff, six attempts per outage and a 30 s stability reset, only for a load that already played; engine failures stay terminal, a running recording is filed as interrupted and restarted after the reload, and an external subtitle file is re-added. Settings.embeddedMpvAutoReconnect (default on) opts out; the player shows 'Reconnecting... attempt N of M'.

Started by Bpl5966 in #1515 and finished by the maintainers in the same PR.

Co-authored-by: Bpl5966 <amine.b1959@gmail.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-04 16:36:14 +02:00

59 lines
1.8 KiB
C++

#pragma once
#include <napi.h>
#include <cstddef>
#include <cstdint>
#include <string>
#include <utility>
#include <vector>
namespace iptvnator {
/** One libmpv option name/value pair handed to a session at creation. */
using EmbeddedMpvExtraOption = std::pair<std::string, std::string>;
/**
* Reads the optional `key=value` string array `createSession()` receives at
* `index`. The Electron side already validated and ordered the lines
* (network defaults first, then the user's options minus the keys the embed
* depends on — see `resolveEmbeddedMpvSessionOptionArguments`), so this only
* splits on the first `=` and skips anything that is not a non-empty pair.
* No libmpv call lives here: each engine applies the pairs itself, because
* on Linux the libmpv symbols are macros over dynamically resolved pointers.
*/
inline std::vector<EmbeddedMpvExtraOption> readEmbeddedMpvExtraOptions(
const Napi::CallbackInfo& info,
size_t index
)
{
std::vector<EmbeddedMpvExtraOption> options;
if (info.Length() <= index || !info[index].IsArray()) {
return options;
}
const auto entries = info[index].As<Napi::Array>();
for (uint32_t i = 0; i < entries.Length(); ++i) {
const Napi::Value entry = entries.Get(i);
if (!entry.IsString()) {
continue;
}
const std::string line = entry.As<Napi::String>().Utf8Value();
const auto separator = line.find('=');
if (
separator == std::string::npos ||
separator == 0 ||
separator + 1 >= line.size()
) {
continue;
}
options.emplace_back(
line.substr(0, separator),
line.substr(separator + 1)
);
}
return options;
}
} // namespace iptvnator