Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/use aligned buffer #124

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Build
# Meson
/build
/_build
/builddir

# vscode
.vscode/
Expand All @@ -29,3 +30,5 @@ __pycache__
# subprojects
subprojects/packagecache
subprojects/pybind11-*

debian
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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
```
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions ext/pylon/gstpylondsnvmmbufferfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@

#include "gstpylondsnvmmbufferfactory.h"

#if defined(__GNUC__)
#include <stdlib.h>
#include <unistd.h>
#endif

#include <cuda_runtime.h>
#include <gst/video/video.h>

Expand Down Expand Up @@ -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
Expand All @@ -111,7 +121,7 @@ void GstPylonDsNvmmBufferFactory::FreeBuffer(void *p_created_buffer,
NvBufSurface *surf = reinterpret_cast<NvBufSurface *>(buffer_context);

NvBufSurfaceDestroy(surf);
g_free(p_created_buffer);
free(p_created_buffer);
}

void GstPylonDsNvmmBufferFactory::DestroyBufferFactory() { delete this; }
4 changes: 3 additions & 1 deletion ext/pylon/gstpylondsnvmmbufferfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
#endif
18 changes: 16 additions & 2 deletions ext/pylon/gstpylonsysmembufferfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,29 @@

#include "gstpylonsysmembufferfactory.h"

#if defined(__GNUC__)
#include <stdlib.h>
#include <unistd.h>
#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; }
3 changes: 3 additions & 0 deletions ext/pylon/gstpylonsysmembufferfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading