Skip to content

added unitialization of the buffers for closing #86

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions camera/v4l2Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,18 @@ bool v4l2Camera::init()
return true;
}

// uninitDevice
bool v4l2Camera::uninitDevice()
{
// uninitialize buffers, otherwise opening the device again will not work properly!
for (int i = 0; i < mBufferCountMMap; ++i) {
if (-1 == munmap(mBuffersMMap[i].ptr, mBuffersMMap[i].buf.length))
printf("v4l2 -- could not unmap buffers properly\n");
return false;
}
free(mBuffersMMap);
return true;
}

// Open
bool v4l2Camera::Open()
Expand All @@ -411,6 +423,11 @@ bool v4l2Camera::Open()
// Close
bool v4l2Camera::Close()
{
// unitialize the buffers before closing the device
if (!uninitDevice()) {
printf("v4l2 -- could not uninitialize device\n");
}

// stop streaming
enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

Expand Down
2 changes: 2 additions & 0 deletions camera/v4l2Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class v4l2Camera
bool initUserPtr();
bool initMMap();

bool uninitDevice();

int mFD;
int mRequestFormat;
uint32_t mRequestWidth;
Expand Down