Skip to content

Commit 3d46536

Browse files
committed
Add device manager object
1 parent 9402b47 commit 3d46536

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

v4l2capture.c

+48
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ typedef struct {
4848
int buffer_count;
4949
} Video_device;
5050

51+
typedef struct {
52+
PyObject_HEAD
53+
int fd;
54+
struct buffer *buffers;
55+
int buffer_count;
56+
} Device_manager;
57+
5158
struct capability {
5259
int id;
5360
const char *name;
@@ -756,6 +763,19 @@ static PyObject *InsertHuffmanTable(PyObject *self, PyObject *args)
756763

757764
// *********************************************************************
758765

766+
static void Device_manager_dealloc(Device_manager *self)
767+
{
768+
self->ob_type->tp_free((PyObject *)self);
769+
}
770+
771+
static int Device_manager_init(Device_manager *self, PyObject *args,
772+
PyObject *kwargs)
773+
{
774+
return 0;
775+
}
776+
777+
// *********************************************************************
778+
759779
static PyMethodDef Video_device_methods[] = {
760780
{"close", (PyCFunction)Video_device_close, METH_NOARGS,
761781
"close()\n\n"
@@ -820,6 +840,25 @@ static PyTypeObject Video_device_type = {
820840
(initproc)Video_device_init
821841
};
822842

843+
// *********************************************************************
844+
845+
static PyMethodDef Device_manager_methods[] = {
846+
{NULL}
847+
};
848+
849+
static PyTypeObject Device_manager_type = {
850+
PyObject_HEAD_INIT(NULL)
851+
0, "v4l2capture.Device_manager", sizeof(Device_manager), 0,
852+
(destructor)Device_manager_dealloc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
853+
0, Py_TPFLAGS_DEFAULT, "Video_device(path)\n\nOpens the video device at "
854+
"the given path and returns an object that can capture images. The "
855+
"constructor and all methods except close may raise IOError.", 0, 0, 0,
856+
0, 0, 0, Device_manager_methods, 0, 0, 0, 0, 0, 0, 0,
857+
(initproc)Device_manager_init
858+
};
859+
860+
// *********************************************************************
861+
823862
static PyMethodDef module_methods[] = {
824863
{ "InsertHuffmanTable", (PyCFunction)InsertHuffmanTable, METH_VARARGS, NULL },
825864
{ NULL, NULL, 0, NULL }
@@ -828,12 +867,18 @@ static PyMethodDef module_methods[] = {
828867
PyMODINIT_FUNC initv4l2capture(void)
829868
{
830869
Video_device_type.tp_new = PyType_GenericNew;
870+
Device_manager_type.tp_new = PyType_GenericNew;
831871

832872
if(PyType_Ready(&Video_device_type) < 0)
833873
{
834874
return;
835875
}
836876

877+
if(PyType_Ready(&Device_manager_type) < 0)
878+
{
879+
return;
880+
}
881+
837882
PyObject *module = Py_InitModule3("v4l2capture", module_methods,
838883
"Capture video with video4linux2.");
839884

@@ -844,4 +889,7 @@ PyMODINIT_FUNC initv4l2capture(void)
844889

845890
Py_INCREF(&Video_device_type);
846891
PyModule_AddObject(module, "Video_device", (PyObject *)&Video_device_type);
892+
Py_INCREF(&Device_manager_type);
893+
PyModule_AddObject(module, "Device_manager", (PyObject *)&Device_manager_type);
894+
847895
}

0 commit comments

Comments
 (0)