Skip to content

Commit 7139816

Browse files
committed
Properly do deinit
1 parent 0e05ba7 commit 7139816

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

v4l2capture.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class Device_manager_cl{
6161
};
6262
typedef Device_manager_cl Device_manager;
6363

64+
static PyObject *Device_manager_stop(Device_manager *self, PyObject *args);
65+
static PyObject *Device_manager_close(Device_manager *self, PyObject *args);
66+
6467
struct capability {
6568
int id;
6669
const char *name;
@@ -205,7 +208,7 @@ static PyObject *Video_device_get_info(Video_device *self)
205208

206209
if(!s)
207210
{
208-
Py_DECREF(set);
211+
Py_DECREF(set);
209212
Py_RETURN_NONE;
210213
}
211214

@@ -849,6 +852,26 @@ void *Device_manager_Worker_thread(void *arg)
849852

850853
static void Device_manager_dealloc(Device_manager *self)
851854
{
855+
//Stop high level threads
856+
for(std::map<std::string, class Device_manager_Worker_thread_args *>::iterator it = self->threadArgStore->begin();
857+
it != self->threadArgStore->end(); it++)
858+
{
859+
PyObject *args = PyTuple_New(1);
860+
PyTuple_SetItem(args, 0, PyString_FromString(it->first.c_str()));
861+
Device_manager_stop(self, args);
862+
Py_DECREF(args);
863+
}
864+
865+
//Close devices
866+
for(std::map<std::string, int>::iterator it = self->fd->begin();
867+
it != self->fd->end(); it++)
868+
{
869+
PyObject *args = PyTuple_New(1);
870+
PyTuple_SetItem(args, 0, PyString_FromString(it->first.c_str()));
871+
Device_manager_close(self, args);
872+
Py_DECREF(args);
873+
}
874+
852875
delete self->fd;
853876
delete self->buffers;
854877
delete self->buffer_counts;

0 commit comments

Comments
 (0)