commit
cf48f2f350
6 files changed
+992
No files matched your search
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
// Converts Echoion's internal PCM (192 kHz stereo S16, delivered in 20 ms
|
||||
// chunks) into TeamSpeak-ready Opus frames: resample to 48 kHz stereo, then
|
||||
// Opus-encode in exact 20 ms (960 samples/ch) frames. A small PCM ring absorbs
|
||||
// the resampler's priming latency so every emitted frame is exactly 960/ch.
|
||||
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
struct SwrContext;
|
||||
struct OpusEncoder;
|
||||
|
||||
namespace Echoion::Standalone
|
||||
{
|
||||
|
||||
class AudioEncoder
|
||||
{
|
||||
public:
|
||||
|
||||
// inRate defaults to Echoion's 192 kHz internal pipeline.
|
||||
explicit AudioEncoder(int bitrate = 96000, int inRate = 192000);
|
||||
~AudioEncoder();
|
||||
|
||||
AudioEncoder(const AudioEncoder&) = delete;
|
||||
AudioEncoder& operator=(const AudioEncoder&) = delete;
|
||||
|
||||
// Feed one chunk of interleaved stereo S16 at inRate. Returns zero or
|
||||
// more complete Opus frames (each a 20 ms packet).
|
||||
std::vector<std::vector<uint8_t>>
|
||||
encode(std::span<const short> interleaved);
|
||||
|
||||
private:
|
||||
|
||||
SwrContext* swr_ = nullptr;
|
||||
OpusEncoder* enc_ = nullptr;
|
||||
int inRate_ = 192000;
|
||||
std::vector<short> pcm_; // resampled 48 kHz interleaved stereo
|
||||
};
|
||||
|
||||
} // namespace Echoion::Standalone
|
||||
@@ -0,0 +1,117 @@
|
||||
#pragma once
|
||||
|
||||
// Implements Echoion's IPluginInterface against the native TeamSpeak UDP
|
||||
// protocol (EchoionProtocol) instead of the TS3 Client Plugin SDK. This is the
|
||||
// single seam that lets the whole Core run as a standalone application: Core
|
||||
// only ever talks to IPluginInterface, so swapping this implementation in for
|
||||
// the plugin drops the TeamSpeak-client dependency entirely.
|
||||
|
||||
#include <PluginInterface.hpp>
|
||||
|
||||
#include "echoion/protocol/Identity.hpp"
|
||||
#include "echoion/protocol/TsClient.hpp"
|
||||
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Standalone
|
||||
{
|
||||
|
||||
class AudioEncoder;
|
||||
|
||||
// Runtime knobs the protocol client needs that ServerConfig does not carry.
|
||||
// Sourced from environment / defaults by main(), so no Core changes are
|
||||
// required.
|
||||
struct StandaloneSettings {
|
||||
std::string identityPath; // where to load/persist the TS identity
|
||||
int securityLevel = 8;
|
||||
int opusBitrate = 96000;
|
||||
};
|
||||
|
||||
class StandaloneClientInterface : public Api::IPluginInterface
|
||||
{
|
||||
public:
|
||||
|
||||
explicit StandaloneClientInterface(StandaloneSettings settings);
|
||||
~StandaloneClientInterface() override;
|
||||
|
||||
// Lifecycle
|
||||
Api::Result<void> initialize() override;
|
||||
Api::Result<void> shutdown() override;
|
||||
|
||||
// Clients
|
||||
[[nodiscard]] Api::Result<std::vector<Api::ClientInfo>>
|
||||
getClients() override;
|
||||
[[nodiscard]] Api::Result<std::optional<Api::ClientInfo>>
|
||||
getClient(uint64_t clientId) override;
|
||||
Api::Result<void> moveClient(uint64_t clientId,
|
||||
uint64_t channelId) override;
|
||||
Api::Result<void> kickClient(uint64_t clientId,
|
||||
const std::string& reason) override;
|
||||
|
||||
// Channels
|
||||
[[nodiscard]] Api::Result<std::vector<Api::ChannelInfo>>
|
||||
getChannels() const override;
|
||||
[[nodiscard]] Api::Result<std::optional<Api::ChannelInfo>>
|
||||
getChannel(uint64_t channelId) const override;
|
||||
|
||||
// Messaging
|
||||
Api::Result<void>
|
||||
sendTextMessage(uint64_t targetId,
|
||||
const std::string& message) override;
|
||||
Api::Result<void>
|
||||
sendChannelMessage(uint64_t channelId,
|
||||
const std::string& message) override;
|
||||
Api::Result<void>
|
||||
sendServerMessage(const std::string& message) override;
|
||||
|
||||
// Audio
|
||||
Api::Result<void>
|
||||
sendAudioData(const std::span<const short>& data) override;
|
||||
Api::Result<void>
|
||||
setWhisperList(const std::vector<uint64_t>& clientIds) override;
|
||||
|
||||
// Connection
|
||||
Api::Result<void>
|
||||
connectToServer(const Api::ServerConfig& config) override;
|
||||
Api::Result<void> disconnectFromServer() override;
|
||||
[[nodiscard]] bool isConnected() const override;
|
||||
Api::Result<void> reconnect() override;
|
||||
|
||||
// Events
|
||||
void
|
||||
registerEventCallback(const Api::EventCallback& cb) override;
|
||||
void
|
||||
unregisterEventCallback(const Api::EventCallback& cb) override;
|
||||
|
||||
private:
|
||||
|
||||
void wireCallbacks();
|
||||
void onCommand(const Protocol::ParsedCommand& parsed);
|
||||
void onTextMessage(const Protocol::CommandParams& params);
|
||||
void broadcast(const Api::PluginEvent& event);
|
||||
void upsertClientGroup(const Protocol::CommandParams& p,
|
||||
bool emitConnected);
|
||||
|
||||
StandaloneSettings settings_;
|
||||
std::unique_ptr<Protocol::Identity> identity_;
|
||||
std::unique_ptr<Protocol::TsClient> client_;
|
||||
std::unique_ptr<AudioEncoder> encoder_;
|
||||
|
||||
Api::ServerConfig currentConfig_{};
|
||||
std::atomic<bool> initialized_{false};
|
||||
|
||||
mutable std::mutex mirrorMutex_;
|
||||
std::map<uint64_t, Api::ClientInfo> clients_;
|
||||
std::map<uint64_t, Api::ChannelInfo> channels_;
|
||||
std::vector<uint64_t> whisperList_;
|
||||
|
||||
std::mutex cbMutex_;
|
||||
std::vector<Api::EventCallback> callbacks_;
|
||||
};
|
||||
|
||||
} // namespace Echoion::Standalone
|
||||
Reference in new issue
Block a user