remove size from NetQueue template arguments

This commit is contained in:
David Bears 2026-01-16 12:05:35 -05:00
parent 7542ee4f8c
commit fabd25be22
No known key found for this signature in database
GPG key ID: FB975E12C69F7177
2 changed files with 21 additions and 16 deletions

View file

@ -131,7 +131,7 @@ void av_frame_free(AVFrame **frame)
#endif // MINGW
VideoProcessor::VideoProcessor()
:_encoded_frame_size(640,480)
: _encoded_out_queue(8), _encoded_frame_size(640,480)
{
//_lastTimeToShowFrame = time(NULL);
_decoded_output_device = NULL ;
@ -350,7 +350,7 @@ bool JPEGVideo::decodeData(const RsVOIPDataChunk& chunk,QImage& image)
return true ;
}
bool JPEGVideo::encodeData(const QImage& image,uint32_t /* size_hint */, NetQueue<RsVOIPDataChunk, 8>& dst)
bool JPEGVideo::encodeData(const QImage& image,uint32_t /* size_hint */, NetQueue<RsVOIPDataChunk>& dst)
{
// check if we make a diff image, or if we use the full frame.
@ -670,7 +670,7 @@ static void frameToImage(QImage& image, const AVFrame *frame) {
}
}
bool FFmpegVideo::encodeData(const QImage& image, uint32_t target_encoding_bitrate, NetQueue<RsVOIPDataChunk, 8>& dst)
bool FFmpegVideo::encodeData(const QImage& image, uint32_t target_encoding_bitrate, NetQueue<RsVOIPDataChunk>& dst)
{
#if LIBAVCODEC_VERSION_MAJOR < 58
if(dst.full()) return false;

View file

@ -30,28 +30,33 @@ extern "C" {
class QVideoOutputDevice ;
template<typename T, int N>
template<typename T>
class NetQueue {
std::array<T, N> arr;
std::atomic<int> mhead = 0;
std::atomic<int> mtail = 0;
std::vector<T> arr;
const unsigned int mask;
std::atomic<unsigned int> mhead = 0;
std::atomic<unsigned int> mtail = 0;
public:
bool full() const { return mhead - mtail == N; }
T& head() { return arr[mhead % N]; }
NetQueue(unsigned int size) : arr(size), mask(size - 1) {
if(size & mask) throw std::invalid_argument("size must be a power of 2");
}
bool full() const { return mhead - mtail == arr.size(); }
T& head() { return arr[mhead & mask]; }
void push() { mhead++; }
bool push(const T& e) { return !full() && ((arr[mhead++ % N] = e), true); }
bool push(const T& e) { return !full() && ((arr[mhead++ & mask] = e), true); }
bool empty() const { return mhead == mtail; }
T& tail() { return arr[mtail % N]; }
T& tail() { return arr[mtail & mask]; }
void pop() { mtail++; }
bool pop(T& e) { return !empty() && ((e = arr[mtail++ % N]), true); }
bool pop(T& e) { return !empty() && ((e = arr[mtail++ & mask]), true); }
};
class VideoCodec
{
public:
virtual bool encodeData(const QImage& Image, uint32_t size_hint, NetQueue<RsVOIPDataChunk, 8>& dst) = 0;
virtual bool encodeData(const QImage& Image, uint32_t size_hint, NetQueue<RsVOIPDataChunk>& dst) = 0;
virtual bool decodeData(const RsVOIPDataChunk& chunk,QImage& image) = 0;
protected:
@ -67,7 +72,7 @@ public:
JPEGVideo() ;
protected:
virtual bool encodeData(const QImage& Image, uint32_t target_encoding_bitrate, NetQueue<RsVOIPDataChunk, 8>& dst) ;
virtual bool encodeData(const QImage& Image, uint32_t target_encoding_bitrate, NetQueue<RsVOIPDataChunk>& dst) ;
virtual bool decodeData(const RsVOIPDataChunk& chunk, QImage& image) ;
static const uint32_t JPEG_VIDEO_FLAGS_DIFFERENTIAL_FRAME = 0x0001 ;
@ -91,7 +96,7 @@ public:
~FFmpegVideo() ;
protected:
virtual bool encodeData(const QImage& Image, uint32_t target_encoding_bitrate, NetQueue<RsVOIPDataChunk, 8>& dst) ;
virtual bool encodeData(const QImage& Image, uint32_t target_encoding_bitrate, NetQueue<RsVOIPDataChunk>& dst) ;
virtual bool decodeData(const RsVOIPDataChunk& chunk,QImage& image) ;
private:
@ -166,7 +171,7 @@ class VideoProcessor
protected:
NetQueue<RsVOIPDataChunk, 8> _encoded_out_queue ;
NetQueue<RsVOIPDataChunk> _encoded_out_queue;
QSize _encoded_frame_size ;
// =====================================================================================