PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusV4L2VideoSource.h
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2  Program: Plus
3  Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4  See License.txt for details.
5  =========================================================Plus=header=end*/
6 
7 #ifndef __vtkPlusV4L2VideoSource_h
8 #define __vtkPlusV4L2VideoSource_h
9 
10 #include "vtkPlusDataCollectionExport.h"
11 #include "vtkPlusDevice.h"
12 
13 // V4L2 includes
14 #include <linux/videodev2.h>
15 
16 class vtkPlusDataSource;
17 
27 class vtkPlusDataCollectionExport vtkPlusV4L2VideoSource : public vtkPlusDevice
28 {
29  enum V4L2_IO_METHOD
30  {
31  IO_METHOD_UNKNOWN,
32  IO_METHOD_READ,
33  IO_METHOD_MMAP,
34  IO_METHOD_USERPTR
35  };
36 
37  struct FrameBuffer
38  {
39  void* start;
40  size_t length;
41  };
42 
43 public:
44  static vtkPlusV4L2VideoSource* New();
46  virtual void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
47 
49  PlusStatus ReadConfiguration(vtkXMLDataElement* config);
51  PlusStatus WriteConfiguration(vtkXMLDataElement* config);
52 
54  bool IsTracker() const
55  { return false;}
56 
59 
61  virtual PlusStatus NotifyConfigured();
62 
63  vtkSetStdStringMacro(DeviceName);
64  vtkGetStdStringMacro(DeviceName);
65 
66 protected:
69 
70  PlusStatus ReadFrame(unsigned int& currentBufferIndex, unsigned int& bytesUsed);
71 
72  PlusStatus ReadFrameFileDescriptor(unsigned int& currentBufferIndex, unsigned int& bytesUsed);
73  PlusStatus ReadFrameMemoryMap(unsigned int& currentBufferIndex, unsigned int& bytesUsed);
74  PlusStatus ReadFrameUserPtr(unsigned int& currentBufferIndex, unsigned int& bytesUsed);
75 
76  PlusStatus InitRead(unsigned int bufferSize);
77  PlusStatus InitMmap();
78  PlusStatus InitUserp(unsigned int bufferSize);
79 
81  virtual PlusStatus InternalDisconnect() VTK_OVERRIDE;
82 
83  virtual PlusStatus InternalStopRecording() VTK_OVERRIDE;
84  virtual PlusStatus InternalStartRecording() VTK_OVERRIDE;
85 
86  // Conversion methods
87  static std::string IOMethodToString(V4L2_IO_METHOD ioMethod);
88  static V4L2_IO_METHOD StringToIOMethod(const std::string& method);
89 
90  static std::string PixelFormatToString(unsigned int format);
91  static unsigned int StringToPixelFormat(const std::string& format);
92 
93  static std::string FieldOrderToString(v4l2_field field);
94  static v4l2_field StringToFieldOrder(const std::string& field);
95 
96 protected:
97  // Configuration variables
98  std::string DeviceName;
99  V4L2_IO_METHOD IOMethod;
100  // If not nullptr, override these settings in InternalConnect
101  std::shared_ptr<unsigned int> FormatWidth;
102  std::shared_ptr<unsigned int> FormatHeight;
103  std::shared_ptr<unsigned int> PixelFormat;
104  std::shared_ptr<v4l2_field> FieldOrder;
105 
106  // State variables
107  int FileDescriptor;
108  FrameBuffer* FrameBuffers;
109  unsigned int BufferCount;
110  vtkPlusDataSource* DataSource;
111  igsioFieldMapType FrameFields;
112  std::shared_ptr<struct v4l2_format> DeviceFormat;
113 
114  // Cached state variable (duplicate of DeviceFormat members, for passing to Plus functions)
115  FrameSizeType ImageSize;
116  uint32_t NumberOfScalarComponents; // Calculated from device format in InternalConnect
117 };
118 
119 #endif
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
Abstract interface for tracker and video devices.
Definition: vtkPlusDevice.h:60
virtual PlusStatus InternalConnect()
igsioStatus PlusStatus
Definition: PlusCommon.h:40
#define VTK_OVERRIDE
Definition: PlusCommon.h:49
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *)
Class for interfacing an V4L2 device and recording frames into a Plus buffer.
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *)
const char * start
Definition: phidget22.h:5116
virtual PlusStatus NotifyConfigured()
virtual PlusStatus InternalUpdate()
static vtkPlusDevice * New()
Interface to a 3D positioning tool, video source, or generalized data stream.