diff options
Diffstat (limited to 'src/camera/veyeimx287m.cpp')
| -rw-r--r-- | src/camera/veyeimx287m.cpp | 88 |
1 files changed, 38 insertions, 50 deletions
diff --git a/src/camera/veyeimx287m.cpp b/src/camera/veyeimx287m.cpp index 04ee7d2..6df5a3e 100644 --- a/src/camera/veyeimx287m.cpp +++ b/src/camera/veyeimx287m.cpp @@ -16,7 +16,6 @@ // orpheus #include "camera/veye_i2c.h" #include "constants.h" -#include "pixels.h" #include "protocols/httpserver.h" #include "veyeimx287m_types.h" @@ -197,6 +196,11 @@ VeyeIMX287m::VeyeIMX287m() {} VeyeIMX287m::~VeyeIMX287m() { + for (auto &t : m_calcPixelsThreads) { + t.request_stop(); + t.join(); + } + for (auto &t : m_rotateThreads) { t.request_stop(); t.join(); @@ -279,6 +283,10 @@ bool VeyeIMX287m::startStream() t = std::jthread{&VeyeIMX287m::rotateFrameLoop, this}; } + for (auto &t : m_calcPixelsThreads) { + t = std::jthread{&VeyeIMX287m::calcPixelsLoop, this}; + } + std::cout << __func__ << " - OK" << std::endl; return true; @@ -453,8 +461,6 @@ bool VeyeIMX287m::initCam() return false; } - const auto width = fmt.fmt.pix_mp.width; - const auto height = fmt.fmt.pix_mp.height; const int num_planes = fmt.fmt.pix_mp.num_planes; std::cout << "num_planes: " << num_planes << std::endl; @@ -553,9 +559,6 @@ bool VeyeIMX287m::initCam() return false; } - m_buffers[i].size = length; - m_buffers[i].padding = 0; - printf("Buffer mapped at address %p.\n", m_buffers[i].mem); ret = ioctl(m_cam_fd, VIDIOC_QBUF, &buf); @@ -580,13 +583,6 @@ bool VeyeIMX287m::initI2C() return m_i2c != nullptr && m_i2c->open(); } -// bool VeyeIMX287m::initHttpServer() -// { -// m_httpServer = std::make_shared<HttpServer>(this); - -// return m_httpServer != nullptr; -// } - void VeyeIMX287m::getFrameLoop(std::stop_token stopToken) { QElapsedTimer t; @@ -598,14 +594,6 @@ void VeyeIMX287m::getFrameLoop(std::stop_token stopToken) continue; } - // std::cout << __func__ << " acquire" << std::endl; - // std::cout << __func__ << " acquired" << std::endl; - // ++processedCounter; - // continue; - - // std::lock_guard lock{m_imageMutexes[bufferIdx]}; - - // auto &image = m_images[bufferIdx]; const auto &image = m_buffers[bufferIdx].image; { @@ -618,44 +606,49 @@ void VeyeIMX287m::getFrameLoop(std::stop_token stopToken) get_elapsed_ns += t.nsecsElapsed(); } - // m_receiverCalculatorSem.main2calc.release(); - // std::cout << __func__ << ": main2calc.release" << std::endl; - // m_receiverCalculatorSem.bufferIdx = bufferIdx; - // m_receiverCalculatorSem.calc2main.acquire(); - // std::cout << __func__ << ": calc2main.acquire" << std::endl; - // std::cout << __func__ << " released" << std::endl; - ++processedCounter; - // return; - - image->rotate(); - const auto pixels = image->sharedPixels(); + m_sync.freeRawBuffers.acquire(); + // TODO: check that queue cannot contain duplicate indices due to ioctl + // TODO: separate copied images from raw buffers + m_sync.rawBufferIndices.enqueue(bufferIdx); + m_sync.usedRawBuffers.release(); + // image->rotate(); + // const auto pixels = image->sharedPixels(); } } void VeyeIMX287m::rotateFrameLoop(std::stop_token stopToken) { - return; while (!stopToken.stop_requested()) { - std::cout << __func__ << std::endl; - - m_receiverCalculatorSem.main2calc.acquire(); - std::cout << __func__ << ": main2calc.acquired" << std::endl; - const auto idx = m_receiverCalculatorSem.bufferIdx; - m_receiverCalculatorSem.calc2main.release(); - std::cout << __func__ << ": calc2main.released" << std::endl; + // std::cout << __func__ << std::endl; + m_sync.usedRawBuffers.acquire(); + const auto idx = m_sync.rawBufferIndices.dequeue(); const auto &image = m_buffers[idx].image; image->rotate(); - std::cout << "rotated" << std::endl; + // const auto pixels = image->sharedPixels(); + m_sync.freeRawBuffers.release(); + + // m_sync.freeRotatedBuffers.acquire(); + // m_sync.rotatedBufferIndices.enqueue(idx); + // m_sync.usedRotatedBuffers.release(); + } +} + +void VeyeIMX287m::calcPixelsLoop(std::stop_token stopToken) +{ + while (!stopToken.stop_requested()) { + m_sync.usedRotatedBuffers.acquire(); + const auto idx = m_sync.rotatedBufferIndices.dequeue(); + const auto &image = m_buffers[idx].image; const auto pixels = image->sharedPixels(); + m_sync.freeRotatedBuffers.release(); } } // TODO: check if some of buffers are being overritten during processing bool VeyeIMX287m::dequeueImageBuffer(size_t &imageIndex) -// TODO: get Image from video_buffer_ptr { static struct timeval curr, prev; static uint16_t counter = 0; @@ -664,6 +657,7 @@ bool VeyeIMX287m::dequeueImageBuffer(size_t &imageIndex) double elapsedTime = (curr.tv_sec - prev.tv_sec) * 1000.0; // sec to ms elapsedTime += (curr.tv_usec - prev.tv_usec) / 1000.0; // us to ms + // TODO: move this shit to some beautiful place if (elapsedTime > 1000. && processedCounter != 0) { fprintf(stderr, "fps: %d\tdropped: %lu sec: %ld " @@ -703,9 +697,7 @@ bool VeyeIMX287m::dequeueImageBuffer(size_t &imageIndex) memset(&buf, 0, sizeof(buf)); memset(planes, 0, sizeof planes); - const auto radxa_buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; - // buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.type = radxa_buf_type; + buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; buf.memory = V4L2_MEMORY_MMAP; buf.length = VIDEO_MAX_PLANES; buf.m.planes = planes; @@ -735,7 +727,7 @@ bool VeyeIMX287m::dequeueImageBuffer(size_t &imageIndex) } imageIndex = buf.index; - // auto &image = m_images[buf.index]; + const auto &image = m_buffers[buf.index].image; image->height = img_height; image->width = img_width; @@ -743,10 +735,6 @@ bool VeyeIMX287m::dequeueImageBuffer(size_t &imageIndex) // image.counters.encoderPosition = RotaryEncoder::instance()->position(); image->counters.measurementCounter = buf.sequence; - // FIXME: git rid of static vars - // if (not m_previousFrameCounter.has_value()) { - // m_previousFrameCounter = buf.sequence; - // } dropped_count += buf.sequence - m_previousFrameCounter.value_or(buf.sequence) - 1; m_previousFrameCounter = buf.sequence; |
