Loading src/preview.cpp +4 −5 Original line number Diff line number Diff line Loading @@ -695,11 +695,10 @@ std::optional<PreviewResult> FFmpegPreviewer::encode_frame(AVFrame* frame, const PreviewService::PreviewService(BlobCache& cache, MediaBackendApi& db, std::size_t render_threads) : cache_(cache), db_(db), render_pool_(render_threads > 0 ? render_threads : std::max(2u, std::min(8u, std::thread::hardware_concurrency() / 2))), io_pool_(std::max(4u, std::min(16u, std::thread::hardware_concurrency()))), render_sem_(std::max<std::size_t>(1, render_threads > 0 ? std::min<std::size_t>(render_threads, io_pool_.size() - 1) : io_pool_.size() - std::max<std::size_t>(2, io_pool_.size() / 3))) {} render_sem_(render_pool_.size()) {} std::string PreviewService::make_key(const std::string& media_id, int width, int height, const std::string& fmt, Loading Loading @@ -767,7 +766,7 @@ std::shared_ptr<const BlobValue> PreviewService::get_or_create_streaming(const M std::uint64_t msize = media.size_bytes; std::string mkind = media.media_kind; auto fut = io_pool_.submit([this, mid, msize, mkind, width, height, fmt, t_seconds, duration]() { auto fut = render_pool_.submit([this, mid, msize, mkind, width, height, fmt, t_seconds, duration]() { std::string err; auto res = ffmpeg_.render_streaming(db_, io_pool_, cache_, mid, msize, mkind, Loading src/preview.h +3 −2 Original line number Diff line number Diff line Loading @@ -82,8 +82,9 @@ private: BlobCache& cache_; MediaBackendApi& db_; FFmpegPreviewer ffmpeg_; ThreadPool io_pool_; // bounded pool for render + prefetch I/O std::counting_semaphore<256> render_sem_; // limits concurrent renders; must be < io_pool_ size to leave threads for prefetch ThreadPool render_pool_; // CPU-heavy FFmpeg decode/encode — never shares threads with I/O ThreadPool io_pool_; // prefetch I/O only — always has free threads for cluster reads std::counting_semaphore<256> render_sem_; // backpressure: rejects after 30s wait std::mutex inflight_mutex_; std::condition_variable inflight_cv_; std::unordered_set<std::string> inflight_; Loading Loading
src/preview.cpp +4 −5 Original line number Diff line number Diff line Loading @@ -695,11 +695,10 @@ std::optional<PreviewResult> FFmpegPreviewer::encode_frame(AVFrame* frame, const PreviewService::PreviewService(BlobCache& cache, MediaBackendApi& db, std::size_t render_threads) : cache_(cache), db_(db), render_pool_(render_threads > 0 ? render_threads : std::max(2u, std::min(8u, std::thread::hardware_concurrency() / 2))), io_pool_(std::max(4u, std::min(16u, std::thread::hardware_concurrency()))), render_sem_(std::max<std::size_t>(1, render_threads > 0 ? std::min<std::size_t>(render_threads, io_pool_.size() - 1) : io_pool_.size() - std::max<std::size_t>(2, io_pool_.size() / 3))) {} render_sem_(render_pool_.size()) {} std::string PreviewService::make_key(const std::string& media_id, int width, int height, const std::string& fmt, Loading Loading @@ -767,7 +766,7 @@ std::shared_ptr<const BlobValue> PreviewService::get_or_create_streaming(const M std::uint64_t msize = media.size_bytes; std::string mkind = media.media_kind; auto fut = io_pool_.submit([this, mid, msize, mkind, width, height, fmt, t_seconds, duration]() { auto fut = render_pool_.submit([this, mid, msize, mkind, width, height, fmt, t_seconds, duration]() { std::string err; auto res = ffmpeg_.render_streaming(db_, io_pool_, cache_, mid, msize, mkind, Loading
src/preview.h +3 −2 Original line number Diff line number Diff line Loading @@ -82,8 +82,9 @@ private: BlobCache& cache_; MediaBackendApi& db_; FFmpegPreviewer ffmpeg_; ThreadPool io_pool_; // bounded pool for render + prefetch I/O std::counting_semaphore<256> render_sem_; // limits concurrent renders; must be < io_pool_ size to leave threads for prefetch ThreadPool render_pool_; // CPU-heavy FFmpeg decode/encode — never shares threads with I/O ThreadPool io_pool_; // prefetch I/O only — always has free threads for cluster reads std::counting_semaphore<256> render_sem_; // backpressure: rejects after 30s wait std::mutex inflight_mutex_; std::condition_variable inflight_cv_; std::unordered_set<std::string> inflight_; Loading