2014-01-27 19:03:46 +08:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* @brief Source file for VideoPlaybackThread class
|
|
|
|
|
* @author Duzy Chan <code@duzy.info>
|
2014-03-21 01:25:17 -05:00
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
2014-01-27 19:03:46 +08:00
|
|
|
*
|
2019-06-09 08:31:04 -04:00
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-16 01:26:26 -04:00
|
|
|
// Copyright (c) 2008-2019 OpenShot Studios, LLC
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2014-03-30 23:21:30 -05:00
|
|
|
|
2020-10-18 07:43:37 -04:00
|
|
|
#include "VideoPlaybackThread.h"
|
2014-01-27 19:03:46 +08:00
|
|
|
|
|
|
|
|
namespace openshot
|
|
|
|
|
{
|
2014-03-23 01:12:29 -05:00
|
|
|
// Constructor
|
2014-01-27 19:03:46 +08:00
|
|
|
VideoPlaybackThread::VideoPlaybackThread(RendererBase *rb)
|
|
|
|
|
: Thread("video-playback"), renderer(rb)
|
|
|
|
|
, render(), reset(false)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 01:12:29 -05:00
|
|
|
// Destructor
|
2014-01-27 19:03:46 +08:00
|
|
|
VideoPlaybackThread::~VideoPlaybackThread()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 01:12:29 -05:00
|
|
|
// Get the currently playing frame number (if any)
|
2017-09-28 16:03:01 -05:00
|
|
|
int64_t VideoPlaybackThread::getCurrentFramePosition()
|
2014-03-21 01:25:17 -05:00
|
|
|
{
|
|
|
|
|
if (frame)
|
|
|
|
|
return frame->number;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-23 01:12:29 -05:00
|
|
|
// Start the thread
|
2014-01-27 19:03:46 +08:00
|
|
|
void VideoPlaybackThread::run()
|
|
|
|
|
{
|
|
|
|
|
while (!threadShouldExit()) {
|
2014-03-23 01:12:29 -05:00
|
|
|
// Make other threads wait on the render event
|
2015-06-01 00:20:14 -07:00
|
|
|
bool need_render = render.wait(500);
|
|
|
|
|
|
2016-04-22 02:43:06 -05:00
|
|
|
if (need_render && frame)
|
2015-06-01 00:20:14 -07:00
|
|
|
{
|
2016-04-21 01:39:17 -05:00
|
|
|
// Debug
|
2019-10-07 13:34:02 -04:00
|
|
|
ZmqLogger::Instance()->AppendDebugMethod("VideoPlaybackThread::run (before render)", "frame->number", frame->number, "need_render", need_render);
|
2016-04-21 01:39:17 -05:00
|
|
|
|
2015-06-01 00:20:14 -07:00
|
|
|
// Render the frame to the screen
|
|
|
|
|
renderer->paint(frame);
|
|
|
|
|
}
|
2016-04-22 02:43:06 -05:00
|
|
|
|
|
|
|
|
// Signal to other threads that the rendered event has completed
|
|
|
|
|
rendered.signal();
|
2014-01-27 19:03:46 +08:00
|
|
|
}
|
2015-06-01 00:20:14 -07:00
|
|
|
|
|
|
|
|
return;
|
2014-01-27 19:03:46 +08:00
|
|
|
}
|
|
|
|
|
}
|