move time-lapse frame grab from tick to rec_loop

This commit is contained in:
2019-11-09 14:14:59 +01:00
parent faff1dd979
commit a00f78de80
4 changed files with 18 additions and 43 deletions

View File

@@ -792,30 +792,24 @@ void App::rec_loop()
rec_running = true;
while(rec_running)
{
std::unique_ptr<PBO> frame;
std::unique_lock<std::mutex> lock(rec_mutex);
rec_cv.wait(lock, [this] { return !(rec_frames.empty() && rec_running); });
if (!rec_running)
break;
if (!rec_frames.empty())
{
if (rec_frames.front())
{
rec_count++;
frame = std::move(rec_frames.front());
}
rec_frames.pop_front();
}
lock.unlock();
if (frame && Canvas::I->m_encoder)
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();
if (Canvas::I->m_encoder && dt > 0.75f && canvas->m_canvas->m_dirty_stroke)
{
canvas->m_canvas->m_dirty_stroke = false;
PBO equirect = Canvas::I->m_layers_merge.gen_equirect_pbo(
Canvas::I->m_encoder->frame_size() / 4);
std::this_thread::yield();
ImageRef img;
img.create(frame->width, frame->height, frame->map());
img.create(equirect.width, equirect.height, equirect.map());
Canvas::I->m_encoder->encode(img);
frame->unmap();
equirect.unmap();
LOG("frame encoded");
update_rec_frames();
}
update_rec_frames();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
}

View File

@@ -79,28 +79,6 @@ void App::tick(float dt)
main->tick(dt);
if (auto* main = layout[main_id])
main->tick(dt);
if (rec_running && Canvas::I->m_encoder)
{
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();
if (dt > 0.75f && canvas->m_canvas->m_dirty_stroke)
{
canvas->m_canvas->m_dirty_stroke = false;
LOG("rec tick");
PBO equirect;
App::I->render_task([&] {
Canvas::I->draw_merge(true);
});
equirect = Canvas::I->m_layers_merge.gen_equirect_pbo(Canvas::I->m_encoder->frame_size() / 4);
{
std::lock_guard<std::mutex> lock(rec_mutex);
rec_frames.emplace_back(std::make_unique<PBO>(std::move(equirect)));
rec_cv.notify_all();
}
}
}
}
void App::resize(float w, float h)

View File

@@ -1162,6 +1162,7 @@ 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

@@ -108,8 +108,10 @@ PBO Layer::gen_equirect_pbo(glm::ivec2 size /*= { 0, 0 }*/)
PBO pbo;
TextureCube cube = gen_cube();
std::this_thread::yield();
RTT latlong;
latlong.create(size.x * 4, size.y * 2);
std::this_thread::yield();
App::I->render_task([&]
{
@@ -129,9 +131,9 @@ PBO Layer::gen_equirect_pbo(glm::ivec2 size /*= { 0, 0 }*/)
latlong.unbindFramebuffer();
});
std::this_thread::yield();
pbo.create(latlong);
std::this_thread::yield();
latlong.destroy();
cube.destroy();
return pbo;