diff --git a/.gitignore b/.gitignore index 7f0ef3e..a41432b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ Build # Meson /build /_build +/builddir # vscode .vscode/ @@ -29,3 +30,5 @@ __pycache__ # subprojects subprojects/packagecache subprojects/pybind11-* + +debian diff --git a/README.md b/README.md index b4daba7..3d69d72 100644 --- a/README.md +++ b/README.md @@ -236,7 +236,7 @@ Pylon features like `ExposureTime` or `Gain` are mapped to the gstreamer propert Set Exposuretime to 2000µs and Gain to 10.3dB: ``` -gst-launch-1.0 pylonsrc cam::ExposureTime=2000 cam::Gain=10.3 ! videoconvert ! autovideosink +gst-launch-1.0 pylonsrc cam::ExposureAuto=0 cam::GainAuto=0 cam::ExposureTime=2000 cam::Gain=10.3 ! videoconvert ! autovideosink ``` Pylon stream grabber parameters like MaxTransferSize or MaxNumBuffer are mapped to the gstreamer properties `stream::MaxTransferSize` and `stream::MaxNumBuffer`. @@ -435,7 +435,7 @@ Install the pylon and codemeter debian packages. They will install into `/opt/py Install the platform dependencies: ``` -sudo apt-get install cmake meson ninja-build debhelper dh-python \ +sudo apt-get install cmake meson ninja-build debhelper dh-python fakeroot\ libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-python3-plugin-loader \ python3 python3-dev python3-pip python3-setuptools pybind11-dev ``` @@ -460,7 +460,7 @@ Install the pylon and codemeter debian packages. They will install into `/opt/py Install the platform dependencies: ``` -sudo apt-get install cmake meson ninja-build debhelper dh-python \ +sudo apt-get install cmake meson ninja-build debhelper dh-python fakeroot\ libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-python3-plugin-loader \ python3 python3-dev python3-pip python3-setuptools pybind11-dev \ deepstream-6.3 # depending on platform deepstream-6.4 or deepstream-7.0 @@ -594,9 +594,7 @@ To test without install: ``` set GST_PLUGIN_PATH=build/ext/pylon -%GSTREAMER_1_0_ROOT_MSVC_X86_64%\bin\gst-launch-1.0.exe - -pylonsrc ! videoconvert ! autovideosink +%GSTREAMER_1_0_ROOT_MSVC_X86_64%\bin\gst-launch-1.0.exe pylonsrc ! videoconvert ! autovideosink ``` To install into main gstreamer directory diff --git a/ext/pylon/gstpylondsnvmmbufferfactory.cpp b/ext/pylon/gstpylondsnvmmbufferfactory.cpp index 378d949..8d4496d 100644 --- a/ext/pylon/gstpylondsnvmmbufferfactory.cpp +++ b/ext/pylon/gstpylondsnvmmbufferfactory.cpp @@ -32,6 +32,11 @@ #include "gstpylondsnvmmbufferfactory.h" +#if defined(__GNUC__) +#include +#include +#endif + #include #include @@ -82,9 +87,14 @@ void GstPylonDsNvmmBufferFactory::AllocateBuffer(size_t buffer_size, intptr_t &buffer_context) { void *buffer_mem = nullptr; - buffer_mem = g_malloc(buffer_size); + const size_t PAGE_SIZE = getpagesize(); + const size_t aligned_buffer_size = RoundUp(buffer_size, PAGE_SIZE); + + int ret = posix_memalign(&buffer_mem, PAGE_SIZE, aligned_buffer_size); + if (ret) + buffer_mem = nullptr; - create_params.params.size = buffer_size; + create_params.params.size = aligned_buffer_size; /* * The optimal approach would be to us the nvsurface being allocated below @@ -111,7 +121,7 @@ void GstPylonDsNvmmBufferFactory::FreeBuffer(void *p_created_buffer, NvBufSurface *surf = reinterpret_cast(buffer_context); NvBufSurfaceDestroy(surf); - g_free(p_created_buffer); + free(p_created_buffer); } void GstPylonDsNvmmBufferFactory::DestroyBufferFactory() { delete this; } diff --git a/ext/pylon/gstpylondsnvmmbufferfactory.h b/ext/pylon/gstpylondsnvmmbufferfactory.h index 1267c56..b81436a 100644 --- a/ext/pylon/gstpylondsnvmmbufferfactory.h +++ b/ext/pylon/gstpylondsnvmmbufferfactory.h @@ -50,9 +50,11 @@ class GstPylonDsNvmmBufferFactory : public GstPylonBufferFactory { virtual void DestroyBufferFactory() override; private: + size_t RoundUp(size_t N, size_t S) { return ((((N) + (S)-1) / (S)) * (S)); } + NvBufSurfaceLayout layout; guint gpu_id; NvBufSurfaceAllocateParams create_params; }; -#endif \ No newline at end of file +#endif diff --git a/ext/pylon/gstpylonsysmembufferfactory.cpp b/ext/pylon/gstpylonsysmembufferfactory.cpp index b64ed06..8192f20 100644 --- a/ext/pylon/gstpylonsysmembufferfactory.cpp +++ b/ext/pylon/gstpylonsysmembufferfactory.cpp @@ -32,15 +32,29 @@ #include "gstpylonsysmembufferfactory.h" +#if defined(__GNUC__) +#include +#include +#endif + void GstPylonSysMemBufferFactory::AllocateBuffer( size_t buffer_size, void **p_created_buffer, intptr_t & /*buffer_context*/) { - *p_created_buffer = g_malloc(buffer_size); + +#if defined(__GNUC__) + const size_t PAGE_SIZE = getpagesize(); + const size_t aligned_buffer_size = RoundUp(buffer_size, PAGE_SIZE); + int ret = posix_memalign(p_created_buffer, PAGE_SIZE, aligned_buffer_size); + if (ret) + *p_created_buffer = nullptr; +#else + *p_created_buffer = malloc(buffer_size); +#endif } void GstPylonSysMemBufferFactory::FreeBuffer(void *p_created_buffer, intptr_t /* buffer_context */) { - g_free(p_created_buffer); + free(p_created_buffer); } void GstPylonSysMemBufferFactory::DestroyBufferFactory() { delete this; } diff --git a/ext/pylon/gstpylonsysmembufferfactory.h b/ext/pylon/gstpylonsysmembufferfactory.h index f238372..275a7d0 100644 --- a/ext/pylon/gstpylonsysmembufferfactory.h +++ b/ext/pylon/gstpylonsysmembufferfactory.h @@ -46,6 +46,9 @@ class GstPylonSysMemBufferFactory : public GstPylonBufferFactory { virtual void FreeBuffer(void *p_created_buffer, intptr_t buffer_context) override; virtual void DestroyBufferFactory() override; + + private: + size_t RoundUp(size_t N, size_t S) { return ((((N) + (S)-1) / (S)) * (S)); } }; #endif