libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
promeki::SDLPlayerWidget Class Reference

Widget that plays frames through an SDLPlayerMediaIO. More...

#include <sdlplayerwidget.h>

Inheritance diagram for promeki::SDLPlayerWidget:
Collaboration diagram for promeki::SDLPlayerWidget:

Public Member Functions

 SDLPlayerWidget (SDLAudioOutput *audio=nullptr, bool useAudioClock=true, ObjectBase *parent=nullptr)
 Constructs an SDLPlayerWidget.
 
MediaIO * mediaIO () const
 Returns the MediaIO the widget consumes frames through.
 
SDLPlayerMediaIOtask () const
 Returns the underlying task (may be useful for tests).
 
FrameCount framesPresented () const
 Total frames the widget has presented since construction.
 
void togglePause ()
 Toggles the playback clock's pause state.
 
bool isPaused () const
 Returns true when the playback clock is paused.
 
- Public Member Functions inherited from promeki::SDLVideoWidget
 SDLVideoWidget (ObjectBase *parent=nullptr)
 Constructs an SDLVideoWidget.
 
 ~SDLVideoWidget ()
 Destructor. Frees the SDL texture.
 
void setPayload (const UncompressedVideoPayload::Ptr &payload)
 Sets the payload to display.
 
void setScaleMode (ScaleMode mode)
 Sets the scaling mode.
 
ScaleMode scaleMode () const
 Returns the current scaling mode.
 

Protected Member Functions

void keyPressEvent (KeyEvent *e) override
 Handles Key_Space by toggling pause.
 
- Protected Member Functions inherited from promeki::SDLVideoWidget
void paintEvent (PaintEvent *e) override
 

Friends

class SDLPlayerMediaIO
 

Additional Inherited Members

- Public Types inherited from promeki::SDLVideoWidget
enum  ScaleMode { ScaleNone , ScaleFit , ScaleStretch }
 Scaling mode for displayed images. More...
 
- Static Public Member Functions inherited from promeki::SDLVideoWidget
static uint32_t mapPixelFormat (const PixelFormat &pd)
 Maps a promeki PixelFormat to an SDL pixel format.
 
static uint32_t mapColorspace (const PixelFormat &pd)
 Maps a promeki PixelFormat to an SDL_Colorspace.
 
static bool isDirectlyMappable (const PixelFormat &pd)
 Returns whether a format can skip CSC conversion on upload.
 

Detailed Description

Widget that plays frames through an SDLPlayerMediaIO.

SDLPlayerWidget subclasses SDLVideoWidget so it paints frames directly, and owns the MediaIO / SDLPlayerMediaIO pair that consumes frames. Clients retrieve the sink via mediaIO and write frames as they would with any MediaIO backend.

Pause control

The widget is the player's keyboard surface. With FocusPolicy::StrongFocus set at construction, the SDL subsystem routes key events here when the app gives it focus (setFocus or explicit SdlSubsystem::setFocusedWidget). The space key toggles the playback clock's pause state; other keys are left unaccepted so the SdlSubsystem walk propagates them up the parent chain.

Ownership

The widget owns the MediaIO, which owns the task. The task holds a back-pointer to this widget so its pull thread can call back into presentImage — safe because the destruction order guarantees the MediaIO (and therefore the task + its threads) is torn down before the widget's bases.

Example
SDLWindow window("player", 1280, 720);
SDLAudioOutput audio(&window);
SDLPlayerWidget player(&audio, true, &window);
player.setFocus();
window.show();
MediaIO *mio = player.mediaIO();
mio->open();
// ... write frames via mio->sink(0)->writeFrame(...) ...
Manages an SDL3 audio output device for playback.
Definition sdlaudiooutput.h:64
Widget that plays frames through an SDLPlayerMediaIO.
Definition sdlplayerwidget.h:71
Top-level SDL window that serves as a root Widget.
Definition sdlwindow.h:47
Thread Safety
Thread-affine — see SDLVideoWidget. Frames may be delivered from any thread via the owned MediaIO sink (which marshals onto its own task threads); only the widget API itself (focus, geometry, lifecycle) is restricted to the SDL event thread.

Constructor & Destructor Documentation

◆ SDLPlayerWidget()

promeki::SDLPlayerWidget::SDLPlayerWidget ( SDLAudioOutput audio = nullptr,
bool  useAudioClock = true,
ObjectBase *  parent = nullptr 
)
explicit

Constructs an SDLPlayerWidget.

Creates the owned SDLPlayerMediaIO / MediaIO pair and sets FocusPolicy::StrongFocus on the widget so the app can setFocus on it to receive key events.

Parameters
audioAudio output (may be nullptr).
useAudioClockPrefer the audio device as the timing source (default true).
parentOptional parent widget / window.

Member Function Documentation

◆ keyPressEvent()

void promeki::SDLPlayerWidget::keyPressEvent ( KeyEvent *  e)
overrideprotected

Handles Key_Space by toggling pause.

All other key codes are left unaccepted so the SDL subsystem's parent-chain walk propagates them upward.

◆ togglePause()

void promeki::SDLPlayerWidget::togglePause ( )

Toggles the playback clock's pause state.

No-op when no MediaIO is currently open (i.e. no pause-capable clock exists yet).


The documentation for this class was generated from the following file: