@@ -19,6 +19,9 @@ using latch = Latch;
1919#include < libcamera/property_ids.h>
2020#include < libcamera/control_ids.h>
2121
22+ #include < sys/ioctl.h>
23+ #include < linux/dma-buf.h>
24+
2225using namespace std ::chrono;
2326using namespace std ::chrono_literals;
2427
@@ -84,11 +87,6 @@ void CameraRunner::start() {
8487 .at (grabber.streamConfiguration ().stream ())
8588 ->planes ();
8689
87- for (int i = 0 ; i < 3 ; i++) {
88- // std::cout << "Plane " << (i + 1) << " has fd " << planes[i].fd.get() << " with offset " << planes[i].offset << std::endl;
89- // std::cout << "Plane " << (i + 1) << " has fd " << planes[i].fd.get() << " with offset " << planes[i].offset << " and pitch " << static_cast<EGLint>(stride / 2) << std::endl;
90- }
91-
9290 std::array<GlHsvThresholder::DmaBufPlaneData, 3 > yuv_data{{
9391 {planes[0 ].fd .get (), static_cast <EGLint>(planes[0 ].offset ),
9492 static_cast <EGLint>(stride)},
@@ -107,7 +105,6 @@ void CameraRunner::start() {
107105 rangeFromColorspace (colorspace),
108106 type);
109107
110-
111108 if (out != 0 ) {
112109 /*
113110 From libcamera docs:
@@ -177,6 +174,15 @@ void CameraRunner::start() {
177174 auto input_ptr = mmaped.at (data.fd );
178175 int bound = m_width * m_height;
179176
177+
178+ {
179+ struct dma_buf_sync dma_sync {};
180+ dma_sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_RW;
181+ int ret = ::ioctl (data.fd , DMA_BUF_IOCTL_SYNC, &dma_sync);
182+ if (ret)
183+ throw std::runtime_error (" failed to start DMA buf sync" );
184+ }
185+
180186 if (m_copyInput) {
181187 for (int i = 0 ; i < bound; i++) {
182188 std::memcpy (color_out_buf + i * 3 , input_ptr + i * 4 , 3 );
@@ -188,6 +194,14 @@ void CameraRunner::start() {
188194 processed_out_buf[i] = input_ptr[i * 4 + 3 ];
189195 }
190196 }
197+
198+ {
199+ struct dma_buf_sync dma_sync {};
200+ dma_sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_RW;
201+ int ret = ::ioctl (data.fd , DMA_BUF_IOCTL_SYNC, &dma_sync);
202+ if (ret)
203+ throw std::runtime_error (" failed to start DMA buf sync" );
204+ }
191205
192206 m_thresholder.returnBuffer (data.fd );
193207 outgoing.set (std::move (mat_pair));
0 commit comments