- setup a IORING_OP_TIMEOUT to drive the frame loop - use the status mark of buffers ahead to supply new IORING_OP_READ - rely on two running framecount cursors with modulus to map onto buffer slots
64 lines
1.6 KiB
C++
64 lines
1.6 KiB
C++
/*
|
||
commons.hpp - common definitions and utils for the io_uring video output demo code
|
||
|
||
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.
|
||
|
||
* ************************************************************************/
|
||
|
||
#ifndef COMMONS_H
|
||
#define COMMONS_H
|
||
|
||
|
||
#include <cstdint>
|
||
#include <iostream>
|
||
#include <chrono>
|
||
#include <string>
|
||
|
||
#include <linux/time_types.h> // for struct __kernel_timespec
|
||
|
||
using std::string;
|
||
using uint = unsigned int;
|
||
using FrameRate = uint;
|
||
|
||
|
||
inline void
|
||
__FAIL (string msg)
|
||
{
|
||
std::cerr << "FAIL: " << msg << std::endl;
|
||
std::abort();
|
||
}
|
||
|
||
/**
|
||
* Marker class: any copy and copy construction prohibited
|
||
*/
|
||
class NonCopyable
|
||
{
|
||
protected:
|
||
~NonCopyable() = default;
|
||
NonCopyable() = default;
|
||
NonCopyable (NonCopyable const&) = delete;
|
||
NonCopyable& operator= (NonCopyable const&) = delete;
|
||
};
|
||
|
||
|
||
|
||
/**
|
||
* Generate a kernel timespec from a given C++ chrono duration
|
||
*/
|
||
template<class REP, class SCALE>
|
||
constexpr struct __kernel_timespec
|
||
asKernelTimespec (std::chrono::duration<REP, SCALE> dur)
|
||
{
|
||
using namespace std::chrono;
|
||
auto secs = duration_cast<seconds>(dur);
|
||
auto nsecs = duration_cast<nanoseconds>(dur - secs);
|
||
return __kernel_timespec{ static_cast<long long> (secs.count())
|
||
, static_cast<long long> (nsecs.count())
|
||
};
|
||
}
|
||
|
||
#endif /*COMMONS_H*/
|