解决taskflow卡顿问题

This commit is contained in:
Nanako 2024-05-21 01:44:36 +08:00
parent b493dc1e0f
commit 1f28dca4ea
4 changed files with 23 additions and 23 deletions

View File

@ -58,6 +58,7 @@ void build_instrument_process_node(const plugin_host* host, std::map<mixer_track
void mixer::init(singleton_initliazer& initliazer) {
singleton_t<mixer>::init(initliazer);
null_channel_node::init();
executor_ = new tf::Executor(std::thread::hardware_concurrency());
auto device_manager = initliazer.require<audio_device_manager>();
zero_track = new dummy_track();
@ -78,6 +79,7 @@ void mixer::release(singleton_release_guard& release_guard) {
delete track;
}
delete zero_track;
delete executor_;
}
dummy_track* mixer::create_dummy_track(const std::string& in_name) {
@ -120,33 +122,27 @@ void mixer::remove_track(mixer_track* track) {
void mixer::process(uint32_t in_frames) {
{
query_timer timer("mixer process");
// tf::Executor executor;
// tf::Taskflow taskflow;
// tf::Task previous_task = taskflow.emplace([] {});
tf::Taskflow taskflow;
tf::Task previous_task = taskflow.emplace([] {});
for (const auto& order: layer_order_) {
for (const auto& layer = layer_tracks_[order]; const auto& track: layer) {
// taskflow.emplace([track, in_frames] {
taskflow.emplace([track, in_frames] {
track->process(in_frames);
// }).succeed(previous_task);
}).succeed(previous_task);
}
// tf::Task new_layer = taskflow.emplace([] {});
// new_layer.succeed(previous_task);
// previous_task = new_layer;
tf::Task new_layer = taskflow.emplace([] {});
new_layer.succeed(previous_task);
previous_task = new_layer;
}
// executor.run(taskflow).wait();
}
{
query_timer timer("mixer post process");
post_process(in_frames);
executor_->run(taskflow).wait();
}
post_process(in_frames);
dummy_track* master = get_master();
master->buffer.multiple(master->volume);
}
void mixer::reset() {
query_timer timer("mixer reset");
for (const auto track: tracks_) {
track->buffer.clear();
}

View File

@ -46,6 +46,7 @@ private:
std::vector<mixer_track*> tracks_;
std::map<int32_t, std::vector<mixer_track*>> layer_tracks_;
std::vector<int32_t> layer_order_;
tf::Executor* executor_;
};
DEFINE_SINGLETON_INSTANCE(mixer)

View File

@ -1,6 +1,5 @@
#include "plugin_host_manager.h"
#include "taskflow/taskflow.hpp"
#include "plugin_host.h"
#include "audio/device/audio_device_manager.h"
@ -17,6 +16,7 @@ void plugin_host_manager::init(singleton_initliazer& initliazer) {
singleton_t<plugin_host_manager>::init(initliazer);
auto* mixer_ptr = initliazer.require<mixer>();
mixer_ptr->on_remove_track.add_raw(this, &plugin_host_manager::on_mixer_track_removed);
executor_ = new tf::Executor(std::thread::hardware_concurrency());
}
void plugin_host_manager::release(singleton_release_guard& release_guard) {
@ -26,6 +26,7 @@ void plugin_host_manager::release(singleton_release_guard& release_guard) {
for (const plugin_host* host: plugin_hosts_) {
delete host;
}
delete executor_;
}
plugin_host* plugin_host_manager::create_instrument_plugin_host(const char* path) {
@ -82,15 +83,14 @@ void plugin_host_manager::register_instrument_plugin(plugin_host* host) {
}
void plugin_host_manager::process(uint32_t in_frames) const {
query_timer timer("host process");
// tf::Executor executor;
// tf::Taskflow taskflow;
tf::Taskflow taskflow;
for (auto host : plugin_hosts_) {
// taskflow.emplace([host, in_frames] {
taskflow.emplace([host, in_frames] {
host->process(in_frames);
// });
});
}
// executor.run(taskflow).wait();
executor_->run(taskflow).wait();
}
void plugin_host_manager::on_mixer_track_removed(mixer_track* track) {

View File

@ -1,6 +1,7 @@
#pragma once
#include "misc/delegates.h"
#include "misc/singleton/singleton.h"
#include "taskflow/taskflow.hpp"
class plugin_host;
class mixer_track;
@ -28,6 +29,8 @@ private:
std::vector<plugin_host*> instrument_plugins_{};
std::vector<plugin_host*> plugin_hosts_{};
tf::Executor* executor_;
};
DEFINE_SINGLETON_INSTANCE(plugin_host_manager)