many different fixes
This commit is contained in:
1 parent
b4073ddf1e
commit
5e1e3d66c4
8 files changed
+116
-59
No files matched your search
+10
-14
@@ -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
|
||||
)
|
||||
@@ -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<float> pooledSamples;
|
||||
// Now using int16_t for direct TeamSpeak compatibility (no float conversion)
|
||||
std::vector<int16_t> 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<float> getSamples() const {
|
||||
if (view.empty()) {
|
||||
return {};
|
||||
}
|
||||
return std::vector<float>(view.data(), view.data() + view.size());
|
||||
// Backwards compatibility - returns the samples
|
||||
[[nodiscard]] std::vector<int16_t> 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<int32_t>(volume * 32768);
|
||||
for (auto& sample : samples) {
|
||||
int32_t scaled = (static_cast<int32_t>(sample) * volInt) / 32768;
|
||||
sample = static_cast<int16_t>(std::clamp(scaled, -32768, 32767));
|
||||
}
|
||||
// Update view to point to new data
|
||||
view = Int16AudioView(samples.data(), samples.size(), channels);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -51,6 +51,17 @@ struct BotConfig {
|
||||
// Alternative: use cookies from browser directly
|
||||
// e.g., "chrome", "firefox", "safari", "edge"
|
||||
std::optional<std::string> 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<std::string> urlShortenerApiUrl; // Custom URL shortener API endpoint
|
||||
};
|
||||
|
||||
struct ServerConfig {
|
||||
|
||||
@@ -64,10 +64,11 @@ public:
|
||||
virtual Result<void> shutdown() = 0;
|
||||
|
||||
// Client operations
|
||||
[[nodiscard]] virtual Result<std::vector<ClientInfo>> getClients() const = 0;
|
||||
[[nodiscard]] virtual Result<std::optional<ClientInfo>> getClient(uint64_t clientId) const = 0;
|
||||
virtual Result<void> moveClient(uint64_t clientId, uint64_t channelId) = 0;
|
||||
virtual Result<void> kickClient(uint64_t clientId, const std::string& reason) = 0;
|
||||
[[nodiscard]] virtual Result<std::vector<ClientInfo>> getClients() = 0;
|
||||
[[nodiscard]] virtual Result<std::optional<ClientInfo>>
|
||||
getClient(uint64_t clientId) = 0;
|
||||
virtual Result<void> moveClient(uint64_t clientId, uint64_t channelId) = 0;
|
||||
virtual Result<void> kickClient(uint64_t clientId, const std::string& reason) = 0;
|
||||
|
||||
// Channel operations
|
||||
[[nodiscard]] virtual Result<std::vector<ChannelInfo>> getChannels() const = 0;
|
||||
@@ -79,8 +80,8 @@ public:
|
||||
virtual Result<void> sendServerMessage(const std::string& message) = 0;
|
||||
|
||||
// Audio
|
||||
virtual Result<void> sendAudioData(const std::span<const uint8_t>& data) = 0;
|
||||
virtual Result<void> setWhisperList(const std::vector<uint64_t>& clientIds) = 0;
|
||||
virtual Result<void> sendAudioData(const std::span<const short>& data) = 0;
|
||||
virtual Result<void> setWhisperList(const std::vector<uint64_t>& clientIds) = 0;
|
||||
|
||||
// Server connection
|
||||
virtual Result<void> connectToServer(const ServerConfig& config) = 0;
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
#include <optional>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include <atomic>
|
||||
|
||||
namespace Echoion::Api {
|
||||
|
||||
@@ -160,21 +163,31 @@ public:
|
||||
|
||||
// ===== Subscriptions =====
|
||||
|
||||
// Add a subscriber
|
||||
Api::Result<void> 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<void> removeSubscriber(uint64_t clientId);
|
||||
// Add a subscriber (by UID)
|
||||
Api::Result<void> addSubscriber(const std::string& uid, const std::string& nickname);
|
||||
|
||||
// Check if client is subscribed
|
||||
[[nodiscard]] Api::Result<bool> isSubscriber(uint64_t clientId);
|
||||
// Remove a subscriber (by UID)
|
||||
Api::Result<void> removeSubscriber(const std::string& uid);
|
||||
|
||||
// Check if client is subscribed (by UID)
|
||||
[[nodiscard]] Api::Result<bool> isSubscriber(const std::string& uid);
|
||||
|
||||
// Get all subscribers
|
||||
[[nodiscard]] Api::Result<std::vector<uint64_t>> getAllSubscribers();
|
||||
[[nodiscard]] Api::Result<std::vector<SubscriberInfo>> getAllSubscribers();
|
||||
|
||||
// Get subscriber count
|
||||
[[nodiscard]] Api::Result<size_t> getSubscriberCount();
|
||||
|
||||
// Clear all subscribers
|
||||
Api::Result<void> clearAllSubscribers();
|
||||
|
||||
// ===== Cache Management =====
|
||||
|
||||
// Clear old history (keep last N entries)
|
||||
@@ -193,6 +206,8 @@ public:
|
||||
|
||||
private:
|
||||
std::unique_ptr<DatabaseImpl> impl_;
|
||||
mutable std::shared_mutex mutex_; // Shared mutex for read/write concurrency
|
||||
std::atomic<bool> shutdown_{false}; // Flag to prevent operations after shutdown
|
||||
};
|
||||
|
||||
// Database manager (singleton)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <queue>
|
||||
#include <atomic>
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
|
||||
namespace Echoion::Api {
|
||||
|
||||
@@ -185,11 +186,11 @@ private:
|
||||
MemoryPool<T>* 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<float> acquireBuffer();
|
||||
[[nodiscard]] PooledPtr<int16_t> acquireBuffer();
|
||||
|
||||
// Get buffer size
|
||||
[[nodiscard]] size_t getBufferSize() const { return bufferSize_; }
|
||||
@@ -210,7 +211,7 @@ public:
|
||||
private:
|
||||
AudioBufferPool() = default;
|
||||
|
||||
std::unique_ptr<MemoryPool<float>> pool_;
|
||||
std::unique_ptr<MemoryPool<int16_t>> 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<int16_t>;
|
||||
|
||||
// Deprecated: Float audio view is no longer used, all audio is int16
|
||||
using FloatAudioView = AudioBufferView<float>;
|
||||
|
||||
} // namespace Echoion::Api
|
||||
@@ -27,10 +27,33 @@ struct TrackInfo {
|
||||
std::optional<std::chrono::milliseconds> duration;
|
||||
TrackSource source;
|
||||
std::string originalUrl;
|
||||
std::optional<std::string> shortenedUrl; // faumaray.ru shortened link
|
||||
std::optional<std::string> streamUrl;
|
||||
std::optional<AudioStreamInfo> 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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user