libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
sdlplayerwidget.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <promeki/namespace.h>
13#include <promeki/mutex.h>
14#include <promeki/atomic.h>
15#include <promeki/framecount.h>
17#include <promeki/uniqueptr.h>
18#include <promeki/mediaio.h>
19
20PROMEKI_NAMESPACE_BEGIN
21
22class SDLAudioOutput;
23class KeyEvent;
24
72 PROMEKI_OBJECT(SDLPlayerWidget, SDLVideoWidget)
73 friend class SDLPlayerMediaIO;
74
75 public:
89 explicit SDLPlayerWidget(SDLAudioOutput *audio = nullptr, bool useAudioClock = true,
90 ObjectBase *parent = nullptr);
91
92 ~SDLPlayerWidget() override;
93
95 MediaIO *mediaIO() const { return _mediaIO.get(); }
96
98 SDLPlayerMediaIO *task() const { return _task; }
99
101 FrameCount framesPresented() const { return FrameCount(_framesPresented.value()); }
102
110
112 bool isPaused() const;
113
114 protected:
122 void keyPressEvent(KeyEvent *e) override;
123
124 private:
125 // Called by the owning @ref SDLPlayerMediaIO on its pull
126 // thread when a new video payload is ready for display.
127 // Stashes the payload and wakes the main thread.
128 void presentVideo(const UncompressedVideoPayload::Ptr &payload);
129
130 // Main-thread handler invoked in response to the wake
131 // event — swaps the stashed payload into the
132 // SDLVideoWidget and triggers a paint on the containing
133 // window.
134 bool renderPending();
135
136 void wakeMainThread();
137 static uint32_t userEventType();
138
139 UniquePtr<SDLPlayerMediaIO> _mediaIO;
140 SDLPlayerMediaIO *_task = nullptr;
141
142 // Main-thread render stash (written by the pull thread,
143 // drained by the main thread).
144 UncompressedVideoPayload::Ptr _pendingPayload;
145 mutable Mutex _pendingMutex;
146 Atomic<bool> _renderScheduled;
147 Atomic<int64_t> _framesPresented;
148};
149
150PROMEKI_NAMESPACE_END
Manages an SDL3 audio output device for playback.
Definition sdlaudiooutput.h:64
MediaIO sink that plays frames through SDL via FrameSync.
Definition sdlplayer.h:62
Widget that plays frames through an SDLPlayerMediaIO.
Definition sdlplayerwidget.h:71
void togglePause()
Toggles the playback clock's pause state.
SDLPlayerMediaIO * task() const
Returns the underlying task (may be useful for tests).
Definition sdlplayerwidget.h:98
FrameCount framesPresented() const
Total frames the widget has presented since construction.
Definition sdlplayerwidget.h:101
SDLPlayerWidget(SDLAudioOutput *audio=nullptr, bool useAudioClock=true, ObjectBase *parent=nullptr)
Constructs an SDLPlayerWidget.
MediaIO * mediaIO() const
Returns the MediaIO the widget consumes frames through.
Definition sdlplayerwidget.h:95
void keyPressEvent(KeyEvent *e) override
Handles Key_Space by toggling pause.
bool isPaused() const
Returns true when the playback clock is paused.
Widget that displays an UncompressedVideoPayload via SDL texture rendering.
Definition sdlvideowidget.h:64