@@ -48,6 +48,13 @@ typedef struct {
48
48
int buffer_count ;
49
49
} Video_device ;
50
50
51
+ typedef struct {
52
+ PyObject_HEAD
53
+ int fd ;
54
+ struct buffer * buffers ;
55
+ int buffer_count ;
56
+ } Device_manager ;
57
+
51
58
struct capability {
52
59
int id ;
53
60
const char * name ;
@@ -756,6 +763,19 @@ static PyObject *InsertHuffmanTable(PyObject *self, PyObject *args)
756
763
757
764
// *********************************************************************
758
765
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
+
759
779
static PyMethodDef Video_device_methods [] = {
760
780
{"close" , (PyCFunction )Video_device_close , METH_NOARGS ,
761
781
"close()\n\n"
@@ -820,6 +840,25 @@ static PyTypeObject Video_device_type = {
820
840
(initproc )Video_device_init
821
841
};
822
842
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
+
823
862
static PyMethodDef module_methods [] = {
824
863
{ "InsertHuffmanTable" , (PyCFunction )InsertHuffmanTable , METH_VARARGS , NULL },
825
864
{ NULL , NULL , 0 , NULL }
@@ -828,12 +867,18 @@ static PyMethodDef module_methods[] = {
828
867
PyMODINIT_FUNC initv4l2capture (void )
829
868
{
830
869
Video_device_type .tp_new = PyType_GenericNew ;
870
+ Device_manager_type .tp_new = PyType_GenericNew ;
831
871
832
872
if (PyType_Ready (& Video_device_type ) < 0 )
833
873
{
834
874
return ;
835
875
}
836
876
877
+ if (PyType_Ready (& Device_manager_type ) < 0 )
878
+ {
879
+ return ;
880
+ }
881
+
837
882
PyObject * module = Py_InitModule3 ("v4l2capture" , module_methods ,
838
883
"Capture video with video4linux2." );
839
884
@@ -844,4 +889,7 @@ PyMODINIT_FUNC initv4l2capture(void)
844
889
845
890
Py_INCREF (& Video_device_type );
846
891
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
+
847
895
}
0 commit comments