OpenShot Library | libopenshot 1.1.1
Loading...
Searching...
No Matches
VideoPlaybackThread.cpp
Go to the documentation of this file.
1
9
10// Copyright (c) 2008-2019 OpenShot Studios, LLC
11//
12// SPDX-License-Identifier: LGPL-3.0-or-later
13
14#include "VideoPlaybackThread.h"
15#include "Logger.h"
16
17#include "Frame.h"
18#include "RendererBase.h"
19#include "Logger.h"
20#include <utility>
21
22namespace openshot
23{
24 // Constructor
25 VideoPlaybackThread::VideoPlaybackThread(RendererBase *rb)
26 : Thread("video-playback"), renderer(rb)
27 , render(), reset(false)
28 {
29 }
30
31 // Destructor
32 VideoPlaybackThread::~VideoPlaybackThread()
33 {
34 }
35
36 // Get the currently playing frame number (if any)
37 int64_t VideoPlaybackThread::getCurrentFramePosition()
38 {
39 std::lock_guard<std::mutex> lock(frame_mutex);
40 return frame ? frame->number : 0;
41 }
42
43 void VideoPlaybackThread::SetFrame(std::shared_ptr<Frame> next_frame)
44 {
45 std::lock_guard<std::mutex> lock(frame_mutex);
46 frame = std::move(next_frame);
47 }
48
49 // Start the thread
50 void VideoPlaybackThread::run()
51 {
52 while (!threadShouldExit()) {
53 // Make other threads wait on the render event
54 bool need_render = render.wait(500);
55 if (threadShouldExit())
56 break;
57 std::shared_ptr<Frame> frame_to_render;
58 if (need_render) {
59 std::lock_guard<std::mutex> lock(frame_mutex);
60 frame_to_render = frame;
61 }
62
63 if (frame_to_render)
64 {
65 // Debug
66 Logger::Instance()->AppendDebugMethod(
67 "VideoPlaybackThread::run (before render)",
68 "frame->number", frame_to_render->number,
69 "need_render", need_render);
70
71 // Render the frame to the screen
72 renderer->paint(frame_to_render);
73 }
74
75 // Signal to other threads that the rendered event has completed
76 rendered.signal();
77 }
78
79 return;
80 }
81}
Header file for Frame class.
Header file for RendererBase class.
Source file for VideoPlaybackThread class.
This is the base class of all Renderers in libopenshot.
This namespace is the default namespace for all code in the openshot library.