@@ -50,12 +50,14 @@ typedef struct {
50
50
int buffer_count;
51
51
} Video_device;
52
52
53
- typedef struct {
53
+ class Device_manager_cl {
54
+ public:
54
55
PyObject_HEAD
55
- std::map<std::string, int > fd;
56
- std::map<std::string, struct buffer *> buffers;
57
- std::map<std::string, int > buffer_count;
58
- } Device_manager;
56
+ std::map<std::string, int > *fd;
57
+ std::map<std::string, struct buffer *> *buffers;
58
+ std::map<std::string, int > *buffer_counts;
59
+ };
60
+ typedef Device_manager_cl Device_manager;
59
61
60
62
struct capability {
61
63
int id;
@@ -767,21 +769,28 @@ static PyObject *InsertHuffmanTable(PyObject *self, PyObject *args)
767
769
768
770
static void Device_manager_dealloc (Device_manager *self)
769
771
{
772
+ delete self->fd ;
773
+ delete self->buffers ;
774
+ delete self->buffer_counts ;
770
775
self->ob_type ->tp_free ((PyObject *)self);
771
776
}
772
777
773
778
static int Device_manager_init (Device_manager *self, PyObject *args,
774
779
PyObject *kwargs)
775
780
{
781
+ self->fd = new std::map<std::string, int >;
782
+ self->buffers = new std::map<std::string, struct buffer *>;
783
+ self->buffer_counts = new std::map<std::string, int >;
776
784
return 0 ;
777
785
}
778
786
779
787
static PyObject *Device_manager_Start (Device_manager *self, PyObject *args)
780
788
// self, dev = None, reqSize=(640, 480), reqFps = 30, fmt = "MJPEG", buffer_count = 10):
781
789
{
790
+
782
791
// Process arguments
783
792
const char *devarg = NULL ;
784
- if (PyTuple_Size (args) < 1 )
793
+ if (PyTuple_Size (args) >= 1 )
785
794
{
786
795
PyObject *pydevarg = PyTuple_GetItem (args, 0 );
787
796
devarg = PyString_AsString (pydevarg);
@@ -799,8 +808,8 @@ static PyObject *Device_manager_Start(Device_manager *self, PyObject *args)
799
808
}
800
809
801
810
// Check this device has not already been start
802
- std::map<std::string, int >::iterator it = self->fd . find (devarg);
803
- if (it!=self->fd . end ())
811
+ std::map<std::string, int >::iterator it = self->fd -> find (devarg);
812
+ if (it!=self->fd -> end ())
804
813
{
805
814
PyErr_Format (PyExc_RuntimeError, " Device already started." );
806
815
Py_RETURN_NONE;
@@ -815,8 +824,8 @@ static PyObject *Device_manager_Start(Device_manager *self, PyObject *args)
815
824
Py_RETURN_NONE;
816
825
}
817
826
818
- self->fd [devarg] = fd;
819
- self->buffers [devarg] = NULL ;
827
+ (* self->fd ) [devarg] = fd;
828
+ (* self->buffers ) [devarg] = NULL ;
820
829
821
830
// Set other parameters for capture
822
831
// TODO
@@ -854,9 +863,9 @@ static PyObject *Device_manager_Start(Device_manager *self, PyObject *args)
854
863
}
855
864
856
865
struct buffer *buffs = (struct buffer *)malloc (reqbuf.count * sizeof (struct buffer ));
857
- self->buffers [devarg] = buffs;
866
+ (* self->buffers ) [devarg] = buffs;
858
867
859
- if (!self-> buffers [devarg] )
868
+ if (!buffs )
860
869
{
861
870
PyErr_NoMemory ();
862
871
Py_RETURN_NONE;
@@ -885,8 +894,8 @@ static PyObject *Device_manager_Start(Device_manager *self, PyObject *args)
885
894
}
886
895
}
887
896
888
- self->buffer_count [devarg] = reqbuf.count ;
889
- buffer_count = self-> buffer_count [devarg] ;
897
+ (* self->buffer_counts ) [devarg] = reqbuf.count ;
898
+ buffer_count = reqbuf. count ;
890
899
891
900
// Send the buffer to the device. Some devices require this to be done
892
901
// before calling 'start'.
@@ -916,7 +925,7 @@ static PyObject *Device_manager_Start(Device_manager *self, PyObject *args)
916
925
Py_RETURN_NONE;
917
926
}
918
927
919
- static PyObject *Device_manager_stop (Video_device *self, PyObject *args)
928
+ static PyObject *Device_manager_stop (Device_manager *self, PyObject *args)
920
929
{
921
930
// Process arguments
922
931
const char *devarg = NULL ;
@@ -930,7 +939,7 @@ static PyObject *Device_manager_stop(Video_device *self, PyObject *args)
930
939
devarg = " /dev/video0" ;
931
940
}
932
941
933
- if (self->fd [devarg] < 0 )
942
+ if ((* self->fd ) [devarg] < 0 )
934
943
{
935
944
PyErr_SetString (PyExc_ValueError, " I/O operation on closed file" );
936
945
Py_RETURN_NONE;
@@ -939,7 +948,7 @@ static PyObject *Device_manager_stop(Video_device *self, PyObject *args)
939
948
enum v4l2_buf_type type;
940
949
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
941
950
942
- if (my_ioctl (self->fd [devarg], VIDIOC_STREAMOFF, &type))
951
+ if (my_ioctl ((* self->fd ) [devarg], VIDIOC_STREAMOFF, &type))
943
952
{
944
953
Py_RETURN_NONE;
945
954
}
@@ -1030,7 +1039,7 @@ static PyTypeObject Device_manager_type = {
1030
1039
PyObject_HEAD_INIT (NULL )
1031
1040
0 , " v4l2capture.Device_manager" , sizeof (Device_manager), 0 ,
1032
1041
(destructor)Device_manager_dealloc, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
1033
- 0 , Py_TPFLAGS_DEFAULT, " Video_device (path)\n\n Opens the video device at "
1042
+ 0 , Py_TPFLAGS_DEFAULT, " Device_manager (path)\n\n Opens the video device at "
1034
1043
" the given path and returns an object that can capture images. The "
1035
1044
" constructor and all methods except close may raise IOError." , 0 , 0 , 0 ,
1036
1045
0 , 0 , 0 , Device_manager_methods, 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
0 commit comments