Plan recording session decisions in app core
This commit is contained in:
54
src/app.cpp
54
src/app.cpp
@@ -5,6 +5,7 @@
|
||||
#include "node_dialog_open.h"
|
||||
#include "node_progress_bar.h"
|
||||
#include "mp4enc.h"
|
||||
#include "app_core/document_recording.h"
|
||||
#include "app_core/document_route.h"
|
||||
#include "app_core/document_session.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
@@ -880,47 +881,70 @@ void App::renderdoc_frame_end()
|
||||
|
||||
void App::rec_clear()
|
||||
{
|
||||
rec_stop();
|
||||
const auto plan = pp::app::plan_recording_clear(
|
||||
rec_running,
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
delete_all_files_in_path(rec_path);
|
||||
true
|
||||
#else
|
||||
false
|
||||
#endif
|
||||
rec_count = 0;
|
||||
);
|
||||
if (plan.stop_running_recording)
|
||||
rec_stop();
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
if (plan.delete_recorded_files)
|
||||
delete_all_files_in_path(rec_path);
|
||||
#endif
|
||||
rec_count = plan.frame_count_after_clear;
|
||||
update_rec_frames();
|
||||
}
|
||||
|
||||
void App::rec_start()
|
||||
{
|
||||
if (!rec_running)
|
||||
const auto plan = pp::app::plan_recording_start(rec_running);
|
||||
switch (plan)
|
||||
{
|
||||
update_rec_frames();
|
||||
rec_thread = std::thread(&App::rec_loop, this);
|
||||
case pp::app::RecordingStartAction::start_thread:
|
||||
break;
|
||||
case pp::app::RecordingStartAction::no_op_already_running:
|
||||
return;
|
||||
}
|
||||
|
||||
update_rec_frames();
|
||||
rec_thread = std::thread(&App::rec_loop, this);
|
||||
}
|
||||
|
||||
void App::rec_stop()
|
||||
{
|
||||
if (rec_running)
|
||||
const auto plan = pp::app::plan_recording_stop(rec_running);
|
||||
switch (plan)
|
||||
{
|
||||
rec_running = false;
|
||||
rec_cv.notify_all();
|
||||
if (rec_thread.joinable())
|
||||
rec_thread.join();
|
||||
update_rec_frames();
|
||||
case pp::app::RecordingStopAction::stop_thread:
|
||||
break;
|
||||
case pp::app::RecordingStopAction::no_op_not_running:
|
||||
return;
|
||||
}
|
||||
|
||||
rec_running = false;
|
||||
rec_cv.notify_all();
|
||||
if (rec_thread.joinable())
|
||||
rec_thread.join();
|
||||
update_rec_frames();
|
||||
}
|
||||
|
||||
void App::rec_export(std::string path)
|
||||
{
|
||||
int progress = 0;
|
||||
int tot = rec_count;
|
||||
const auto plan = pp::app::plan_recording_export(static_cast<std::size_t>(rec_count));
|
||||
auto pb = layout[main_id]->add_child<NodeProgressBar>();
|
||||
pb->m_progress->SetWidthP(0);
|
||||
pb->m_title->set_text("Exporting MP4 movie");
|
||||
pb->m_total = plan.progress_total;
|
||||
pb->m_count = 0;
|
||||
|
||||
/*
|
||||
#if defined(__IOS__) || defined(__OSX__)
|
||||
export_mp4(rec_path, width, height, rec_count, ^(float) {
|
||||
pb->m_progress->SetWidthP((float)progress / tot * 100.f);
|
||||
pb->increment();
|
||||
});
|
||||
#endif
|
||||
*/
|
||||
|
||||
63
src/app_core/document_recording.h
Normal file
63
src/app_core/document_recording.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <limits>
|
||||
|
||||
namespace pp::app {
|
||||
|
||||
enum class RecordingStartAction {
|
||||
start_thread,
|
||||
no_op_already_running,
|
||||
};
|
||||
|
||||
enum class RecordingStopAction {
|
||||
stop_thread,
|
||||
no_op_not_running,
|
||||
};
|
||||
|
||||
struct RecordingClearPlan {
|
||||
bool stop_running_recording = false;
|
||||
bool delete_recorded_files = false;
|
||||
int frame_count_after_clear = 0;
|
||||
};
|
||||
|
||||
struct RecordingExportPlan {
|
||||
std::size_t frame_count = 0;
|
||||
int progress_total = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] constexpr RecordingStartAction plan_recording_start(bool is_running) noexcept
|
||||
{
|
||||
return is_running
|
||||
? RecordingStartAction::no_op_already_running
|
||||
: RecordingStartAction::start_thread;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr RecordingStopAction plan_recording_stop(bool is_running) noexcept
|
||||
{
|
||||
return is_running
|
||||
? RecordingStopAction::stop_thread
|
||||
: RecordingStopAction::no_op_not_running;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr RecordingClearPlan plan_recording_clear(
|
||||
bool is_running,
|
||||
bool platform_deletes_recorded_files) noexcept
|
||||
{
|
||||
return {
|
||||
is_running,
|
||||
platform_deletes_recorded_files,
|
||||
0,
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr RecordingExportPlan plan_recording_export(std::size_t frame_count) noexcept
|
||||
{
|
||||
const auto max_progress_total = static_cast<std::size_t>(std::numeric_limits<int>::max());
|
||||
return {
|
||||
frame_count,
|
||||
frame_count > max_progress_total ? std::numeric_limits<int>::max() : static_cast<int>(frame_count),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user