diff --git a/include/libmegapixels.h b/include/libmegapixels.h index d7e33a8..06c78aa 100644 --- a/include/libmegapixels.h +++ b/include/libmegapixels.h @@ -90,6 +90,9 @@ libmegapixels_load_file(libmegapixels_devconfig **config, const char *file); EXPORT int libmegapixels_open(libmegapixels_camera *camera); +EXPORT void +libmegapixels_close(libmegapixels_camera *camera); + EXPORT unsigned int libmegapixels_select_mode(libmegapixels_camera *camera, libmegapixels_mode *mode); diff --git a/src/pipeline.c b/src/pipeline.c index 9047d99..80275e7 100644 --- a/src/pipeline.c +++ b/src/pipeline.c @@ -169,6 +169,30 @@ libmegapixels_open(libmegapixels_camera *camera) return 0; } +void +libmegapixels_close(libmegapixels_camera *camera) +{ + if (camera->media_fd != 0) { + close(camera->media_fd); + camera->media_fd = 0; + } + if (camera->sensor_fd != 0) { + close(camera->sensor_fd); + camera->sensor_fd = 0; + } + if (camera->video_fd != 0) { + close(camera->video_fd); + camera->video_fd = 0; + } + + for (int i = 0; i < camera->num_handles; i++) { + if (camera->handles[i]->fd != 0) { + close(camera->handles[i]->fd); + camera->handles[i]->fd = 0; + } + } +} + unsigned int libmegapixels_select_mode(libmegapixels_camera *camera, libmegapixels_mode *mode) {