Skip to content

Commit

Permalink
Add communication to video processor
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Nov 28, 2024
1 parent 61065d0 commit 127914a
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 17 deletions.
4 changes: 3 additions & 1 deletion include/grabber/linux/v4l2/V4L2Worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <utils/PixelFormat.h>
#include <base/Grabber.h>
#include <utils/Components.h>
#include <base/AutomaticToneMapping.h>

#include <turbojpeg.h>

Expand All @@ -32,7 +33,7 @@ class V4L2Worker : public QThread
unsigned __cropBottom, unsigned __cropRight,
quint64 __currentFrame, qint64 __frameBegin,
int __hdrToneMappingEnabled, uint8_t* __lutBuffer,
bool __qframe, bool __directAccess, QString __deviceName);
bool __qframe, bool __directAccess, QString __deviceName, AutomaticToneMapping* __automaticToneMapping);

void startOnThisThread();
void run() override;
Expand Down Expand Up @@ -76,6 +77,7 @@ class V4L2Worker : public QThread
bool _qframe;
bool _directAccess;
QString _deviceName;
AutomaticToneMapping* _automaticToneMapping;
};

class V4L2WorkerManager : public QObject
Expand Down
4 changes: 3 additions & 1 deletion include/grabber/osx/AVF/AVFWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <utils/PixelFormat.h>
#include <base/Grabber.h>
#include <utils/Components.h>
#include <base/AutomaticToneMapping.h>



Expand All @@ -38,7 +39,7 @@ class AVFWorker : public QThread
unsigned __cropBottom, unsigned __cropRight,
quint64 __currentFrame, qint64 __frameBegin,
int __hdrToneMappingEnabled, uint8_t* __lutBuffer, bool __qframe,
bool __directAccess, QString __deviceName);
bool __directAccess, QString __deviceName, AutomaticToneMapping* __automaticToneMapping);

void startOnThisThread();
void run() override;
Expand Down Expand Up @@ -78,6 +79,7 @@ class AVFWorker : public QThread
bool _qframe;
bool _directAccess;
QString _deviceName;
AutomaticToneMapping* _automaticToneMapping;
};

class AVFWorkerManager : public QObject
Expand Down
4 changes: 3 additions & 1 deletion include/grabber/windows/MF/MFWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <utils/PixelFormat.h>
#include <base/Grabber.h>
#include <utils/Components.h>
#include <base/AutomaticToneMapping.h>

#include <turbojpeg.h>

Expand All @@ -27,7 +28,7 @@ class MFWorker : public QThread
unsigned __cropBottom, unsigned __cropRight,
quint64 __currentFrame, qint64 __frameBegin,
int __hdrToneMappingEnabled, uint8_t* __lutBuffer, bool __qframe,
bool __directAccess, QString __deviceName);
bool __directAccess, QString __deviceName, AutomaticToneMapping* __automaticToneMapping);

void startOnThisThread();
void run() override;
Expand Down Expand Up @@ -69,6 +70,7 @@ class MFWorker : public QThread
bool _qframe;
bool _directAccess;
QString _deviceName;
AutomaticToneMapping* _automaticToneMapping;
};

class MFWorkerManager : public QObject
Expand Down
3 changes: 2 additions & 1 deletion include/utils/FrameDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <image/ColorRgb.h>
#include <image/Image.h>
#include <utils/PixelFormat.h>
#include <base/AutomaticToneMapping.h>

// some stuff for HDR tone mapping
#define LUT_INDEX(y,u,v) ((y + (u<<8) + (v<<16))*3)
Expand All @@ -24,7 +25,7 @@ class FrameDecoder

static void processQImage(
const uint8_t* data, const uint8_t* dataUV, int width, int height, int lineLength,
const PixelFormat pixelFormat, const uint8_t* lutBuffer, Image<ColorRgb>& outputImage, bool toneMapping = true);
const PixelFormat pixelFormat, const uint8_t* lutBuffer, Image<ColorRgb>& outputImage, bool toneMapping = true, AutomaticToneMapping* automaticToneMapping = nullptr);

static void processSystemImageBGRA(Image<ColorRgb>& image, int targetSizeX, int targetSizeY,
int startX, int startY,
Expand Down
2 changes: 1 addition & 1 deletion sources/grabber/linux/v4l2/V4L2Grabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ bool V4L2Grabber::process_image(v4l2_buffer* buf, const void* frameImageBuffer,
(uint8_t*)frameImageBuffer, size, _actualWidth, _actualHeight, _lineLength,
_cropLeft, _cropTop, _cropBottom, _cropRight,
processFrameIndex, InternalClock::nowPrecise(), _hdrToneMappingEnabled,
(_lutBufferInit) ? _lut.data() : nullptr, _qframe, directAccess, _deviceName);
(_lutBufferInit) ? _lut.data() : nullptr, _qframe, directAccess, _deviceName, _automaticToneMapping.prepare());

if (_V4L2WorkerManager.workersCount > 1)
_V4L2WorkerManager.workers[i]->start();
Expand Down
8 changes: 5 additions & 3 deletions sources/grabber/linux/v4l2/V4L2Worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ V4L2Worker::V4L2Worker() :
_frameBegin(0),
_hdrToneMappingEnabled(0),
_lutBuffer(nullptr),
_qframe(false)
_qframe(false),
_automaticToneMapping(nullptr)
{

}
Expand All @@ -154,7 +155,7 @@ void V4L2Worker::setup(unsigned int __workerIndex, v4l2_buffer* __v4l2Buf, Pixel
uint8_t* __sharedData, int __size, int __width, int __height, int __lineLength,
uint __cropLeft, uint __cropTop, uint __cropBottom, uint __cropRight,
quint64 __currentFrame, qint64 __frameBegin,
int __hdrToneMappingEnabled, uint8_t* __lutBuffer, bool __qframe, bool __directAccess, QString __deviceName)
int __hdrToneMappingEnabled, uint8_t* __lutBuffer, bool __qframe, bool __directAccess, QString __deviceName, AutomaticToneMapping* __automaticToneMapping)
{
_workerIndex = __workerIndex;
memcpy(&_v4l2Buf, __v4l2Buf, sizeof(v4l2_buffer));
Expand All @@ -175,6 +176,7 @@ void V4L2Worker::setup(unsigned int __workerIndex, v4l2_buffer* __v4l2Buf, Pixel
_qframe = __qframe;
_directAccess = __directAccess;
_deviceName = __deviceName;
_automaticToneMapping = __automaticToneMapping;
}

v4l2_buffer* V4L2Worker::GetV4L2Buffer()
Expand All @@ -201,7 +203,7 @@ void V4L2Worker::runMe()
{
Image<ColorRgb> image(_width >> 1, _height >> 1);
FrameDecoder::processQImage(
_sharedData, nullptr, _width, _height, _lineLength, _pixelFormat, _lutBuffer, image, _hdrToneMappingEnabled);
_sharedData, nullptr, _width, _height, _lineLength, _pixelFormat, _lutBuffer, image, _hdrToneMappingEnabled, _automaticToneMapping);

image.setBufferCacheSize();
if (!_directAccess)
Expand Down
2 changes: 1 addition & 1 deletion sources/grabber/osx/AVF/AVFGrabber.mm
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ - (void)captureOutput:(AVCaptureOutput *)output didOutputSampleBuffer:(CMSampleB
(uint8_t*)frameImageBuffer, size, _actualWidth, _actualHeight, _lineLength,
_cropLeft, _cropTop, _cropBottom, _cropRight,
processFrameIndex, InternalClock::nowPrecise(), _hdrToneMappingEnabled,
(_lutBufferInit) ? _lut.data() : nullptr, _qframe, directAccess, _deviceName);
(_lutBufferInit) ? _lut.data() : nullptr, _qframe, directAccess, _deviceName, _automaticToneMapping.prepare());

if (_AVFWorkerManager.workersCount > 1)
_AVFWorkerManager.workers[i]->start();
Expand Down
8 changes: 5 additions & 3 deletions sources/grabber/osx/AVF/AVFWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ AVFWorker::AVFWorker() :
_frameBegin(0),
_hdrToneMappingEnabled(0),
_lutBuffer(nullptr),
_qframe(false)
_qframe(false),
_automaticToneMapping(nullptr)
{

}
Expand All @@ -154,7 +155,7 @@ void AVFWorker::setup(unsigned int __workerIndex, PixelFormat __pixelFormat,
uint8_t* __sharedData, int __size, int __width, int __height, int __lineLength,
uint __cropLeft, uint __cropTop, uint __cropBottom, uint __cropRight,
quint64 __currentFrame, qint64 __frameBegin,
int __hdrToneMappingEnabled, uint8_t* __lutBuffer, bool __qframe, bool __directAccess, QString __deviceName)
int __hdrToneMappingEnabled, uint8_t* __lutBuffer, bool __qframe, bool __directAccess, QString __deviceName, AutomaticToneMapping* __automaticToneMapping)
{
_workerIndex = __workerIndex;
_lineLength = __lineLength;
Expand All @@ -173,6 +174,7 @@ void AVFWorker::setup(unsigned int __workerIndex, PixelFormat __pixelFormat,
_qframe = __qframe;
_directAccess = __directAccess;
_deviceName = __deviceName;
_automaticToneMapping = __automaticToneMapping;

_localBuffer.resize((size_t)__size + 1);

Expand All @@ -193,7 +195,7 @@ void AVFWorker::runMe()
{
Image<ColorRgb> image(_width >> 1, _height >> 1);
FrameDecoder::processQImage(
_localBuffer.data(), nullptr, _width, _height, _lineLength, _pixelFormat, _lutBuffer, image);
_localBuffer.data(), nullptr, _width, _height, _lineLength, _pixelFormat, _lutBuffer, image, _hdrToneMappingEnabled, _automaticToneMapping);

image.setBufferCacheSize();
if (!_directAccess)
Expand Down
2 changes: 1 addition & 1 deletion sources/grabber/windows/MF/MFGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ bool MFGrabber::process_image(const void* frameImageBuffer, int size)
(uint8_t*)frameImageBuffer, size, _actualWidth, _actualHeight, _lineLength,
_cropLeft, _cropTop, _cropBottom, _cropRight,
processFrameIndex, InternalClock::nowPrecise(), _hdrToneMappingEnabled,
(_lutBufferInit) ? _lut.data() : nullptr, _qframe, directAccess, _deviceName);
(_lutBufferInit) ? _lut.data() : nullptr, _qframe, directAccess, _deviceName, _automaticToneMapping.prepare());

if (_MFWorkerManager.workersCount > 1)
_MFWorkerManager.workers[i]->start();
Expand Down
8 changes: 5 additions & 3 deletions sources/grabber/windows/MF/MFWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ MFWorker::MFWorker() :
_hdrToneMappingEnabled(0),
_lutBuffer(nullptr),
_qframe(false),
_directAccess(false)
_directAccess(false),
_automaticToneMapping(nullptr)
{

}
Expand All @@ -155,7 +156,7 @@ void MFWorker::setup(unsigned int __workerIndex, PixelFormat __pixelFormat,
uint8_t* __sharedData, int __size, int __width, int __height, int __lineLength,
uint __cropLeft, uint __cropTop, uint __cropBottom, uint __cropRight,
quint64 __currentFrame, qint64 __frameBegin,
int __hdrToneMappingEnabled, uint8_t* __lutBuffer, bool __qframe, bool __directAccess, QString __deviceName)
int __hdrToneMappingEnabled, uint8_t* __lutBuffer, bool __qframe, bool __directAccess, QString __deviceName, AutomaticToneMapping* __automaticToneMapping)
{
_workerIndex = __workerIndex;
_lineLength = __lineLength;
Expand All @@ -174,6 +175,7 @@ void MFWorker::setup(unsigned int __workerIndex, PixelFormat __pixelFormat,
_qframe = __qframe;
_directAccess = __directAccess;
_deviceName = __deviceName;
_automaticToneMapping = __automaticToneMapping;

_localBuffer.resize((size_t)__size + 1);

Expand All @@ -199,7 +201,7 @@ void MFWorker::runMe()
{
Image<ColorRgb> image(_width >> 1, _height >> 1);
FrameDecoder::processQImage(
_localBuffer.data(), nullptr, _width, _height, _lineLength, _pixelFormat, _lutBuffer, image, _hdrToneMappingEnabled);
_localBuffer.data(), nullptr, _width, _height, _lineLength, _pixelFormat, _lutBuffer, image, _hdrToneMappingEnabled, _automaticToneMapping);

image.setBufferCacheSize();
if (!_directAccess)
Expand Down
2 changes: 1 addition & 1 deletion sources/utils/FrameDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ void FrameDecoder::processImage(

void FrameDecoder::processQImage(
const uint8_t* data, const uint8_t* dataUV, int width, int height, int lineLength,
const PixelFormat pixelFormat, const uint8_t* lutBuffer, Image<ColorRgb>& outputImage, bool toneMapping)
const PixelFormat pixelFormat, const uint8_t* lutBuffer, Image<ColorRgb>& outputImage, bool toneMapping, AutomaticToneMapping* automaticToneMapping)
{
uint32_t ind_lutd;
uint8_t buffer[8];
Expand Down

0 comments on commit 127914a

Please sign in to comment.