2026-07-11 19:03:31 +02:00
|
|
|
|
/*
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
* ************************************************************************/
|
|
|
|
|
|
|
2026-07-14 19:27:27 +02:00
|
|
|
|
|
|
|
|
|
|
#include "commons.hpp"
|
|
|
|
|
|
#include "egl-display.hpp"
|
|
|
|
|
|
#include "gtk-uring-app.hpp"
|
|
|
|
|
|
|
2026-07-11 19:03:31 +02:00
|
|
|
|
#include <iostream>
|
2026-07-14 19:27:27 +02:00
|
|
|
|
#include <memory>
|
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
|
|
|
|
using std::unique_ptr;
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------hard-coded-config--
|
|
|
|
|
|
//-----------------hard-coded-config--
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UringVideoPlayer
|
|
|
|
|
|
{
|
|
|
|
|
|
Glib::Dispatcher dispatchFrame_;
|
|
|
|
|
|
EglDisplay videoDisplayer_;
|
|
|
|
|
|
std::thread proactorThread_;
|
2026-07-14 20:16:18 +02:00
|
|
|
|
|
2026-07-14 19:27:27 +02:00
|
|
|
|
public:
|
|
|
|
|
|
UringVideoPlayer (Gtk::Window& appWindow)
|
|
|
|
|
|
: videoDisplayer_{appWindow, dispatchFrame_}
|
|
|
|
|
|
, proactorThread_{[this]{ playVideo(); }}
|
|
|
|
|
|
{ }
|
2026-07-14 20:16:18 +02:00
|
|
|
|
|
|
|
|
|
|
void terminate();
|
2026-07-14 19:27:27 +02:00
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
void
|
|
|
|
|
|
playVideo()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unique_ptr<UringVideoPlayer>
|
|
|
|
|
|
launchPlayer (Gtk::Window& appWindow)
|
|
|
|
|
|
{
|
2026-07-14 20:16:18 +02:00
|
|
|
|
appWindow.resize (EglDisplay::VIDEO_WIDTH, EglDisplay::VIDEO_HEIGHT);
|
|
|
|
|
|
|
2026-07-14 19:27:27 +02:00
|
|
|
|
auto player = std::make_unique<UringVideoPlayer> (appWindow);
|
2026-07-14 20:16:18 +02:00
|
|
|
|
|
2026-07-14 19:27:27 +02:00
|
|
|
|
return player;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2026-07-14 20:16:18 +02:00
|
|
|
|
UringVideoPlayer::terminate()
|
2026-07-14 19:27:27 +02:00
|
|
|
|
{
|
2026-07-14 20:16:18 +02:00
|
|
|
|
///// signal stop to proactor
|
|
|
|
|
|
videoDisplayer_.cleanUp();
|
2026-07-14 19:27:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-11 19:03:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
|
main (int, const char*[])
|
|
|
|
|
|
{
|
2026-07-14 19:27:27 +02:00
|
|
|
|
return GtkUringApp<UringVideoPlayer>{"io-uring-demo"}
|
|
|
|
|
|
.onClick (launchPlayer)
|
2026-07-14 20:16:18 +02:00
|
|
|
|
.onClose ([](auto& player){ player.terminate();})
|
2026-07-14 19:27:27 +02:00
|
|
|
|
.run();
|
2026-07-11 19:03:31 +02:00
|
|
|
|
}
|