diff --git a/plugins/VOIP/gui/VideoProcessor.cpp b/plugins/VOIP/gui/VideoProcessor.cpp index cc7b72291..947169deb 100644 --- a/plugins/VOIP/gui/VideoProcessor.cpp +++ b/plugins/VOIP/gui/VideoProcessor.cpp @@ -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& dst) +bool JPEGVideo::encodeData(const QImage& image,uint32_t /* size_hint */, NetQueue& 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& dst) +bool FFmpegVideo::encodeData(const QImage& image, uint32_t target_encoding_bitrate, NetQueue& dst) { #if LIBAVCODEC_VERSION_MAJOR < 58 if(dst.full()) return false; diff --git a/plugins/VOIP/gui/VideoProcessor.h b/plugins/VOIP/gui/VideoProcessor.h index a747ec344..a8b99eb4d 100644 --- a/plugins/VOIP/gui/VideoProcessor.h +++ b/plugins/VOIP/gui/VideoProcessor.h @@ -30,28 +30,33 @@ extern "C" { class QVideoOutputDevice ; -template +template class NetQueue { - std::array arr; - std::atomic mhead = 0; - std::atomic mtail = 0; + std::vector arr; + const unsigned int mask; + std::atomic mhead = 0; + std::atomic 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& dst) = 0; + virtual bool encodeData(const QImage& Image, uint32_t size_hint, NetQueue& 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& dst) ; + virtual bool encodeData(const QImage& Image, uint32_t target_encoding_bitrate, NetQueue& 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& dst) ; + virtual bool encodeData(const QImage& Image, uint32_t target_encoding_bitrate, NetQueue& dst) ; virtual bool decodeData(const RsVOIPDataChunk& chunk,QImage& image) ; private: @@ -166,7 +171,7 @@ class VideoProcessor protected: - NetQueue _encoded_out_queue ; + NetQueue _encoded_out_queue; QSize _encoded_frame_size ; // =====================================================================================