notify rec_loop on draw_commit

This commit is contained in:
2019-11-09 14:58:15 +01:00
parent a00f78de80
commit 7b544522cf
3 changed files with 27 additions and 8 deletions

View File

@@ -792,10 +792,12 @@ void App::rec_loop()
rec_running = true;
while(rec_running)
{
auto t_now = std::chrono::high_resolution_clock::now();
float dt = std::chrono::duration<float>(t_now - canvas->m_canvas->m_disrty_stroke_time).count();
std::unique_lock<std::mutex> lock(rec_mutex);
rec_cv.wait(lock/*, [this] { return !(rec_frames.empty() && rec_running); }*/);
if (!rec_running)
break;
if (Canvas::I->m_encoder && dt > 0.75f && canvas->m_canvas->m_dirty_stroke)
if (Canvas::I->m_encoder)
{
canvas->m_canvas->m_dirty_stroke = false;
PBO equirect = Canvas::I->m_layers_merge.gen_equirect_pbo(
@@ -805,11 +807,9 @@ void App::rec_loop()
img.create(equirect.width, equirect.height, equirect.map());
Canvas::I->m_encoder->encode(img);
equirect.unmap();
LOG("frame encoded");
LOG("rec frame encoded");
update_rec_frames();
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
}

View File

@@ -431,6 +431,7 @@ void Canvas::stroke_draw()
{
if (!(m_current_stroke && m_current_stroke->has_sample()))
{
stroke_commit_timelapse();
//stroke_draw_mix({ 0,0 }, { m_mixer.getWidth(), m_mixer.getHeight() });
return;
}
@@ -741,7 +742,6 @@ void Canvas::stroke_commit()
m_dirty = false;
m_dirty_stroke = true; // new stroke ready for timelapse capture
m_disrty_stroke_time = std::chrono::steady_clock::now();
App::I->redraw = true;
// save viewport and clear color states
@@ -923,6 +923,25 @@ void Canvas::stroke_commit()
action->m_canvas = this;
//action->m_stroke = std::move(m_current_stroke);
ActionManager::add(action);
stroke_commit_timelapse();
}
void Canvas::stroke_commit_timelapse()
{
if (m_encoder)
{
auto t_now = std::chrono::high_resolution_clock::now();
float dt = std::chrono::duration<float>(t_now - m_disrty_stroke_time).count();
if (dt > 2.f && m_dirty_stroke && App::I->rec_mutex.try_lock())
{
draw_merge(true);
App::I->rec_mutex.unlock();
App::I->rec_cv.notify_one();
LOG("rec frame generated");
m_dirty_stroke = false;
m_disrty_stroke_time = std::chrono::steady_clock::now();
}
}
}
void Canvas::draw_merge(bool draw_checkerboard, std::array<bool, 6> faces /*= SIXPLETTE(false)*/)
@@ -1162,7 +1181,6 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array<bool, 6> faces /*= SI
m_layers_merge.rtt(plane_index).unbindFramebuffer();
}
draw_merge(true);
}
void Canvas::stroke_update(glm::vec3 point, float pressure)

View File

@@ -208,6 +208,7 @@ public:
void stroke_end();
void stroke_cancel();
void stroke_commit();
void stroke_commit_timelapse();
void draw_merge(bool draw_checkerboard, std::array<bool, 6> faces = SIXPLETTE(true));
void clear(const glm::vec4& color = { 1, 1, 1, 0 });
void clear_all();