This implies a basic decision regarding the buffer and state data to use, and how this can be defined, parameterised and passed between threads. I decided to place separation of domains first and to prefer using a functional callback over using a shared data structure.
93 lines
1.9 KiB
C++
93 lines
1.9 KiB
C++
/*
|
||
demo-uring.cpp - async file IO with io_uring
|
||
|
||
Copyright (C)
|
||
2026, Hermann Vosseler <Ichthyostega@web.de>
|
||
|
||
This program is free software; you can redistribute it and/or modify it
|
||
under the terms of the GNU GPL version 2+ See the LICENSE file for details.
|
||
|
||
* ************************************************************************/
|
||
|
||
|
||
#include "commons.hpp"
|
||
#include "egl-display.hpp"
|
||
#include "gtk-uring-app.hpp"
|
||
|
||
#include <iostream>
|
||
#include <memory>
|
||
#include <thread>
|
||
|
||
using std::unique_ptr;
|
||
|
||
//-----------------hard-coded-config--
|
||
const size_t RING_SIZ = 5;
|
||
|
||
const uint VIDEO_WIDTH = 320;
|
||
const uint VIDEO_HEIGHT = 240;
|
||
//-----------------hard-coded-config--
|
||
|
||
|
||
class UringVideoPlayer
|
||
{
|
||
using VideoDisplay = EglDisplay<uint8_t, VIDEO_WIDTH,VIDEO_HEIGHT>;
|
||
using Buffer = VideoDisplay::Buffer;
|
||
|
||
Glib::Dispatcher dispatchFrame_;
|
||
VideoDisplay videoDisplayer_;
|
||
std::thread proactorThread_;
|
||
|
||
public:
|
||
UringVideoPlayer (Gtk::Window& appWindow)
|
||
: videoDisplayer_{appWindow, dispatchFrame_, [this]{ return retrieveCurrFrame(); }}
|
||
, proactorThread_{[this]{ playVideo(); }}
|
||
{ }
|
||
|
||
void terminate();
|
||
|
||
private:
|
||
void
|
||
playVideo()
|
||
{
|
||
// allocate buffer data structure
|
||
// initialise URing
|
||
// ++ proactor-loop ++
|
||
}
|
||
|
||
Buffer*
|
||
retrieveCurrFrame()
|
||
{
|
||
///////OOO threadsafe hand-over of current frame data
|
||
}
|
||
};
|
||
|
||
|
||
unique_ptr<UringVideoPlayer>
|
||
launchPlayer (Gtk::Window& appWindow)
|
||
{
|
||
appWindow.resize (VIDEO_WIDTH, VIDEO_HEIGHT);
|
||
|
||
auto player = std::make_unique<UringVideoPlayer> (appWindow);
|
||
|
||
return player;
|
||
}
|
||
|
||
|
||
|
||
void
|
||
UringVideoPlayer::terminate()
|
||
{
|
||
///// signal stop to proactor
|
||
videoDisplayer_.cleanUp();
|
||
}
|
||
|
||
|
||
|
||
int
|
||
main (int, const char*[])
|
||
{
|
||
return GtkUringApp<UringVideoPlayer>{"io-uring-demo"}
|
||
.onClick (launchPlayer)
|
||
.onClose ([](auto& player){ player.terminate();})
|
||
.run();
|
||
}
|