From 5e1e3d66c4dc8da169a0c0753d86484aa9022948 Mon Sep 17 00:00:00 2001 From: faumaray Date: Tue, 3 Feb 2026 05:07:40 +0300 Subject: [PATCH] many different fixes --- CMakeLists.txt | 24 ++++++++----------- include/echoion/api/AudioTypes.hpp | 29 +++++++++++++---------- include/echoion/api/ConfigTypes.hpp | 11 +++++++++ include/echoion/api/CoreInterface.hpp | 13 ++++++----- include/echoion/api/Database.hpp | 29 +++++++++++++++++------ include/echoion/api/MemoryPool.hpp | 13 +++++++---- include/echoion/api/TrackTypes.hpp | 23 +++++++++++++++++++ include/echoion/api/Types.hpp | 33 ++++++++++++++------------- 8 files changed, 116 insertions(+), 59 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c7977f..115de41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,18 +30,14 @@ else() target_compile_options(EchoionApi INTERFACE -Wall -Wextra -Wpedantic) endif() -# Installation (header-only library, no archive) -include(GNUInstallDirs) -install(TARGETS EchoionApi - EXPORT EchoionApiTargets -) - -install(EXPORT EchoionApiTargets - FILE EchoionApiTargets.cmake - NAMESPACE Echoion:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/EchoionApi -) - -install(DIRECTORY include/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +# PackageProject.cmake configuration +packageProject( + NAME EchoionApi + VERSION ${PROJECT_VERSION} + NAMESPACE Echoion + BINARY_DIR ${PROJECT_BINARY_DIR} + INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include + INCLUDE_DESTINATION include + COMPATIBILITY SameMajorVersion + DISABLE_VERSION_SUFFIX YES ) diff --git a/include/echoion/api/AudioTypes.hpp b/include/echoion/api/AudioTypes.hpp index 2d21efb..70c1307 100644 --- a/include/echoion/api/AudioTypes.hpp +++ b/include/echoion/api/AudioTypes.hpp @@ -55,34 +55,39 @@ struct AudioStreamInfo { HwAccelType hwAccelType = HwAccelType::None; }; -// Zero-copy decoded audio using pooled memory +// Zero-copy decoded audio using pooled memory (int16 for direct playback) struct DecodedAudio { // Use pooled buffer instead of std::vector for zero-copy - PooledPtr pooledSamples; + // Now using int16_t for direct TeamSpeak compatibility (no float conversion) + std::vector samples; // Non-owning view into the data - FloatAudioView view; + Int16AudioView view; uint32_t sampleRate; uint32_t channels; std::chrono::milliseconds timestamp; - // Backwards compatibility - creates a copy - [[nodiscard]] std::vector getSamples() const { - if (view.empty()) { - return {}; - } - return std::vector(view.data(), view.data() + view.size()); + // Backwards compatibility - returns the samples + [[nodiscard]] std::vector getSamples() const { + return samples; } // Check if valid [[nodiscard]] bool isValid() const { - return !view.empty(); + return !samples.empty(); } - // Apply volume in-place + // Apply volume in-place (int16 version) void applyVolume(float volume) { - view.applyGain(volume); + if (samples.empty()) return; + int32_t volInt = static_cast(volume * 32768); + for (auto& sample : samples) { + int32_t scaled = (static_cast(sample) * volInt) / 32768; + sample = static_cast(std::clamp(scaled, -32768, 32767)); + } + // Update view to point to new data + view = Int16AudioView(samples.data(), samples.size(), channels); } }; diff --git a/include/echoion/api/ConfigTypes.hpp b/include/echoion/api/ConfigTypes.hpp index 91aa331..b90205a 100644 --- a/include/echoion/api/ConfigTypes.hpp +++ b/include/echoion/api/ConfigTypes.hpp @@ -51,6 +51,17 @@ struct BotConfig { // Alternative: use cookies from browser directly // e.g., "chrome", "firefox", "safari", "edge" std::optional cookiesFromBrowser; + + // yt-dlp concurrent resolution settings + // Number of concurrent yt-dlp processes for playlist track resolution (1-8, default: 4) + size_t ytDlpMaxConcurrent = 4; + + // Enable async yt-dlp execution for better performance + bool ytDlpAsyncEnabled = true; + + // URL shortening settings + bool enableUrlShortening = true; // Enable faumaray.ru link shortening + std::optional urlShortenerApiUrl; // Custom URL shortener API endpoint }; struct ServerConfig { diff --git a/include/echoion/api/CoreInterface.hpp b/include/echoion/api/CoreInterface.hpp index dc5bc45..bebcfcb 100644 --- a/include/echoion/api/CoreInterface.hpp +++ b/include/echoion/api/CoreInterface.hpp @@ -64,10 +64,11 @@ public: virtual Result shutdown() = 0; // Client operations - [[nodiscard]] virtual Result> getClients() const = 0; - [[nodiscard]] virtual Result> getClient(uint64_t clientId) const = 0; - virtual Result moveClient(uint64_t clientId, uint64_t channelId) = 0; - virtual Result kickClient(uint64_t clientId, const std::string& reason) = 0; + [[nodiscard]] virtual Result> getClients() = 0; + [[nodiscard]] virtual Result> + getClient(uint64_t clientId) = 0; + virtual Result moveClient(uint64_t clientId, uint64_t channelId) = 0; + virtual Result kickClient(uint64_t clientId, const std::string& reason) = 0; // Channel operations [[nodiscard]] virtual Result> getChannels() const = 0; @@ -79,8 +80,8 @@ public: virtual Result sendServerMessage(const std::string& message) = 0; // Audio - virtual Result sendAudioData(const std::span& data) = 0; - virtual Result setWhisperList(const std::vector& clientIds) = 0; + virtual Result sendAudioData(const std::span& data) = 0; + virtual Result setWhisperList(const std::vector& clientIds) = 0; // Server connection virtual Result connectToServer(const ServerConfig& config) = 0; diff --git a/include/echoion/api/Database.hpp b/include/echoion/api/Database.hpp index 36408c2..f544280 100644 --- a/include/echoion/api/Database.hpp +++ b/include/echoion/api/Database.hpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include namespace Echoion::Api { @@ -160,21 +163,31 @@ public: // ===== Subscriptions ===== - // Add a subscriber - Api::Result addSubscriber(uint64_t clientId); + // Subscriber info + struct SubscriberInfo { + std::string uid; + std::string nickname; + std::chrono::system_clock::time_point subscribedAt; + }; - // Remove a subscriber - Api::Result removeSubscriber(uint64_t clientId); + // Add a subscriber (by UID) + Api::Result addSubscriber(const std::string& uid, const std::string& nickname); - // Check if client is subscribed - [[nodiscard]] Api::Result isSubscriber(uint64_t clientId); + // Remove a subscriber (by UID) + Api::Result removeSubscriber(const std::string& uid); + + // Check if client is subscribed (by UID) + [[nodiscard]] Api::Result isSubscriber(const std::string& uid); // Get all subscribers - [[nodiscard]] Api::Result> getAllSubscribers(); + [[nodiscard]] Api::Result> getAllSubscribers(); // Get subscriber count [[nodiscard]] Api::Result getSubscriberCount(); + // Clear all subscribers + Api::Result clearAllSubscribers(); + // ===== Cache Management ===== // Clear old history (keep last N entries) @@ -193,6 +206,8 @@ public: private: std::unique_ptr impl_; + mutable std::shared_mutex mutex_; // Shared mutex for read/write concurrency + std::atomic shutdown_{false}; // Flag to prevent operations after shutdown }; // Database manager (singleton) diff --git a/include/echoion/api/MemoryPool.hpp b/include/echoion/api/MemoryPool.hpp index 7e367ad..707582a 100644 --- a/include/echoion/api/MemoryPool.hpp +++ b/include/echoion/api/MemoryPool.hpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace Echoion::Api { @@ -185,11 +186,11 @@ private: MemoryPool* pool_ = nullptr; }; -// Specialized audio buffer pool +// Specialized audio buffer pool for int16 (direct TeamSpeak compatibility) class AudioBufferPool { public: static constexpr size_t DEFAULT_BUFFER_SIZE = 1920; // 48000Hz * 2ch * 20ms - static constexpr size_t DEFAULT_POOL_SIZE = 256; // ~7.5MB for float buffers + static constexpr size_t DEFAULT_POOL_SIZE = 256; // ~1MB for int16 buffers static AudioBufferPool& instance(); @@ -198,7 +199,7 @@ public: void shutdown(); // Get a buffer (returns nullptr if pool exhausted) - [[nodiscard]] PooledPtr acquireBuffer(); + [[nodiscard]] PooledPtr acquireBuffer(); // Get buffer size [[nodiscard]] size_t getBufferSize() const { return bufferSize_; } @@ -210,7 +211,7 @@ public: private: AudioBufferPool() = default; - std::unique_ptr> pool_; + std::unique_ptr> pool_; size_t bufferSize_ = DEFAULT_BUFFER_SIZE; }; @@ -282,6 +283,10 @@ private: size_t channels_ = 2; }; +// Audio buffer view types - using int16 (short) for direct TeamSpeak compatibility +using Int16AudioView = AudioBufferView; + +// Deprecated: Float audio view is no longer used, all audio is int16 using FloatAudioView = AudioBufferView; } // namespace Echoion::Api diff --git a/include/echoion/api/TrackTypes.hpp b/include/echoion/api/TrackTypes.hpp index 1d4bc2f..ce71690 100644 --- a/include/echoion/api/TrackTypes.hpp +++ b/include/echoion/api/TrackTypes.hpp @@ -27,10 +27,33 @@ struct TrackInfo { std::optional duration; TrackSource source; std::string originalUrl; + std::optional shortenedUrl; // faumaray.ru shortened link std::optional streamUrl; std::optional audioInfo; std::chrono::system_clock::time_point addedAt; std::string requestedBy; + + // Format track as markdown link: [Title](shortenedUrl) + // Only uses shortened URL (faumaray), returns empty string if not available + [[nodiscard]] std::string formatWithLink() const { + if (shortenedUrl.has_value() && !shortenedUrl->empty()) { + return std::format("[{}]({})", title, *shortenedUrl); + } + return std::format("[{}]", title); // No link if no shortened URL + } + + // Format track with artist and link + // Only uses shortened URL (faumaray), returns text only if not available + [[nodiscard]] std::string formatWithArtistAndLink() const { + std::string displayTitle = title; + if (!artist.empty()) { + displayTitle = std::format("{} by {}", title, artist); + } + if (shortenedUrl.has_value() && !shortenedUrl->empty()) { + return std::format("[{}]({})", displayTitle, *shortenedUrl); + } + return displayTitle; // No link if no shortened URL + } }; struct PlaylistInfo { diff --git a/include/echoion/api/Types.hpp b/include/echoion/api/Types.hpp index 6f4862f..03759d7 100644 --- a/include/echoion/api/Types.hpp +++ b/include/echoion/api/Types.hpp @@ -14,22 +14,23 @@ namespace Echoion::Api { using namespace std::chrono_literals; enum class ErrorCode : uint32_t { - Success = 0, - InvalidArgument, - NotFound, - AlreadyExists, - NetworkError, - ParseError, - AudioError, - PluginError, - InvalidUrl, - NotAuthenticated, - Unauthorized, - PermissionDenied, - ServiceUnavailable, - DatabaseError, - NotSupported, - UnknownError + Success = 0, + InvalidArgument, + NotFound, + AlreadyExists, + NetworkError, + ParseError, + AudioError, + PluginError, + InvalidUrl, + NotAuthenticated, + Unauthorized, + PermissionDenied, + ServiceUnavailable, + DatabaseError, + NotSupported, + NotInitialized, + UnknownError }; struct Error {