Plan recording worker wake decisions
This commit is contained in:
23
src/app.cpp
23
src/app.cpp
@@ -783,21 +783,30 @@ void App::rec_loop()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(rec_mutex);
|
||||
rec_cv.wait(lock/*, [this] { return !(rec_frames.empty() && rec_running); }*/);
|
||||
if (!rec_running)
|
||||
auto* legacy_canvas = Canvas::I;
|
||||
auto* canvas_document = canvas ? canvas->m_canvas.get() : nullptr;
|
||||
auto* encoder = legacy_canvas ? legacy_canvas->m_encoder.get() : nullptr;
|
||||
const auto plan = pp::app::plan_recording_worker_iteration(
|
||||
rec_running,
|
||||
encoder != nullptr,
|
||||
legacy_canvas != nullptr && canvas_document != nullptr);
|
||||
if (!plan.continue_running)
|
||||
break;
|
||||
|
||||
if (Canvas::I->m_encoder)
|
||||
if (plan.encode_frame && legacy_canvas && canvas_document && encoder)
|
||||
{
|
||||
canvas->m_canvas->m_dirty_stroke = false;
|
||||
PBO equirect = Canvas::I->m_layers_merge.gen_equirect_pbo(
|
||||
Canvas::I->m_encoder->frame_size());
|
||||
if (plan.clear_dirty_stroke)
|
||||
canvas_document->m_dirty_stroke = false;
|
||||
PBO equirect = legacy_canvas->m_layers_merge.gen_equirect_pbo(
|
||||
encoder->frame_size());
|
||||
std::this_thread::yield();
|
||||
ImageRef img;
|
||||
img.create(equirect.width, equirect.height, equirect.map());
|
||||
Canvas::I->m_encoder->encode(img);
|
||||
encoder->encode(img);
|
||||
equirect.unmap();
|
||||
LOG("rec frame encoded");
|
||||
update_rec_frames();
|
||||
if (plan.update_frame_label)
|
||||
update_rec_frames();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,13 @@ struct RecordingExportPlan {
|
||||
int progress_total = 0;
|
||||
};
|
||||
|
||||
struct RecordingWorkerIterationPlan {
|
||||
bool continue_running = true;
|
||||
bool encode_frame = false;
|
||||
bool clear_dirty_stroke = false;
|
||||
bool update_frame_label = false;
|
||||
};
|
||||
|
||||
class RecordingServices {
|
||||
public:
|
||||
virtual ~RecordingServices() = default;
|
||||
@@ -77,6 +84,20 @@ public:
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr RecordingWorkerIterationPlan plan_recording_worker_iteration(
|
||||
bool is_running_after_wake,
|
||||
bool has_encoder,
|
||||
bool has_canvas_document) noexcept
|
||||
{
|
||||
const bool encode = is_running_after_wake && has_encoder && has_canvas_document;
|
||||
return {
|
||||
.continue_running = is_running_after_wake,
|
||||
.encode_frame = encode,
|
||||
.clear_dirty_stroke = encode,
|
||||
.update_frame_label = encode,
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status execute_recording_start_action(
|
||||
RecordingStartAction action,
|
||||
RecordingServices& services)
|
||||
|
||||
Reference in New Issue
Block a user