Fix callback

This commit is contained in:
Benau 2017-04-10 08:53:55 +08:00
parent ab10f335e9
commit bcf996e291
3 changed files with 25 additions and 4 deletions

@ -68,6 +68,7 @@
#include "utils/vs.hpp"
#include <irrlicht.h>
#include <chrono>
/* Build-time check that the Irrlicht we're building against works for us.
* Should help prevent distros building against an incompatible library.
@ -647,9 +648,22 @@ void IrrDriver::initDevice()
[] (const char* s, void* user_data) { MessageQueue::add
(MessageQueue::MT_GENERIC, _("Video saved in \"%s\".", s));
}, NULL);
static std::chrono::high_resolution_clock::time_point tp;
ogrRegIntCallback(OGR_CBT_PROGRESS_RECORDING,
[] (const int i, void* user_data)
{ Log::info("Recorder", "%d%% of video encoding finished", i);}, NULL);
{
std::chrono::high_resolution_clock::time_point* timer =
(std::chrono::high_resolution_clock::time_point*)user_data;
auto rate = std::chrono::high_resolution_clock::now() -
*timer;
float t = std::chrono::duration_cast<std::chrono::
duration<float> >(rate).count();
if (t > 3.0f)
{
*timer = std::chrono::high_resolution_clock::now();
Log::info("Recorder", "%d%% of video encoding finished", i);
}
}, &tp);
#endif

@ -221,10 +221,10 @@ void CaptureLibrary::captureConversion(CaptureLibrary* cl)
{
runCallback(OGR_CBT_WAIT_RECORDING, NULL);
}
cl->m_display_progress.store(true);
cl->m_jpg_list.emplace_back((uint8_t*)NULL, 0, 0);
cl->m_jpg_list_ready.notify_one();
ulj.unlock();
cl->m_display_progress.store(!cl->m_destroy.load());
cl->m_video_enc_thread.join();
cl->m_display_progress.store(false);
std::string f = Recorder::writeMKV(getSavedName() + ".video",
@ -253,7 +253,8 @@ void CaptureLibrary::captureConversion(CaptureLibrary* cl)
const bool too_slow = cl->m_fbi_list.size() > 50;
if (too_slow)
{
runCallback(OGR_CBT_SLOW_RECORDING, NULL);
if (!cl->m_destroy.load())
runCallback(OGR_CBT_SLOW_RECORDING, NULL);
delete [] fbi;
cl->m_fbi_list.pop_front();
for (auto& p : cl->m_fbi_list)

@ -117,16 +117,22 @@ namespace Recorder
{
cl->getJPGList()->clear();
ul.unlock();
if (cl->displayingProgress())
{
int rate = 100;
runCallback(OGR_CBT_PROGRESS_RECORDING, &rate);
}
break;
}
cl->getJPGList()->pop_front();
ul.unlock();
if (!cl->getDestroy() && cl->displayingProgress())
if (cl->displayingProgress())
{
if (last_size == -1.0f)
last_size = (float)(cl->getJPGList()->size());
cur_finished_count += frame_count;
int rate = (int)(cur_finished_count / last_size * 100.0f);
rate = rate > 100 ? 100 : rate;
runCallback(OGR_CBT_PROGRESS_RECORDING, &rate);
}
uint8_t* yuv = NULL;