VideoStream.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "libfreenect.hpp"
4 #include "PS1080.h"
5 #include "Utility.hpp"
6 
7 
8 namespace FreenectDriver
9 {
11  {
12  private:
13  unsigned int frame_id; // number each frame
14 
15  virtual OniStatus setVideoMode(OniVideoMode requested_mode) = 0;
16  virtual void populateFrame(void* data, OniFrame* frame) const = 0;
17 
18  protected:
19  static const OniSensorType sensor_type;
21  bool running; // buildFrame() does something iff true
24  bool mirroring;
25 
26  public:
28  frame_id(1),
29  device(device),
30  mirroring(false)
31  {
32  // joy of structs
33  memset(&cropping, 0, sizeof(cropping));
34  memset(&video_mode, 0, sizeof(video_mode));
35  }
36  //~VideoStream() { stop(); }
37 
38  void buildFrame(void* data, uint32_t timestamp)
39  {
40  if (!running)
41  return;
42 
44  frame->frameIndex = frame_id++;
45  frame->timestamp = timestamp;
46  frame->videoMode = video_mode;
47  frame->width = video_mode.resolutionX;
48  frame->height = video_mode.resolutionY;
49 
50  populateFrame(data, frame);
51  raiseNewFrame(frame);
52  getServices().releaseFrame(frame);
53  }
54 
55  // from StreamBase
56 
58  {
59  running = true;
60  return ONI_STATUS_OK;
61  }
62  void stop() { running = false; }
63 
64  // only add to property handlers if the property is generic to all children
65  // otherwise, implement in child and call these in default case
66  OniBool isPropertySupported(int propertyId)
67  {
68  switch(propertyId)
69  {
73  return true;
74  default:
75  return false;
76  }
77  }
78 
79  virtual OniStatus getProperty(int propertyId, void* data, int* pDataSize)
80  {
81  switch (propertyId)
82  {
83  default:
84  case ONI_STREAM_PROPERTY_HORIZONTAL_FOV: // float: radians
85  case ONI_STREAM_PROPERTY_VERTICAL_FOV: // float: radians
88  case ONI_STREAM_PROPERTY_STRIDE: // int
90  // camera
92  case ONI_STREAM_PROPERTY_AUTO_EXPOSURE: // OniBool
93  // xn
94  case XN_STREAM_PROPERTY_INPUT_FORMAT: // unsigned long long
95  case XN_STREAM_PROPERTY_CROPPING_MODE: // XnCroppingMode
97 
98  case ONI_STREAM_PROPERTY_VIDEO_MODE: // OniVideoMode*
99  if (*pDataSize != sizeof(OniVideoMode))
100  {
101  LogError("Unexpected size for ONI_STREAM_PROPERTY_VIDEO_MODE");
102  return ONI_STATUS_ERROR;
103  }
104  *(static_cast<OniVideoMode*>(data)) = video_mode;
105  return ONI_STATUS_OK;
106 
107  case ONI_STREAM_PROPERTY_CROPPING: // OniCropping*
108  if (*pDataSize != sizeof(OniCropping))
109  {
110  LogError("Unexpected size for ONI_STREAM_PROPERTY_CROPPING");
111  return ONI_STATUS_ERROR;
112  }
113  *(static_cast<OniCropping*>(data)) = cropping;
114  return ONI_STATUS_OK;
115 
116  case ONI_STREAM_PROPERTY_MIRRORING: // OniBool
117  if (*pDataSize != sizeof(OniBool))
118  {
119  LogError("Unexpected size for ONI_STREAM_PROPERTY_MIRRORING");
120  return ONI_STATUS_ERROR;
121  }
122  *(static_cast<OniBool*>(data)) = mirroring;
123  return ONI_STATUS_OK;
124  }
125  }
126  virtual OniStatus setProperty(int propertyId, const void* data, int dataSize)
127  {
128  switch (propertyId)
129  {
130  default:
131  case ONI_STREAM_PROPERTY_HORIZONTAL_FOV: // float: radians
132  case ONI_STREAM_PROPERTY_VERTICAL_FOV: // float: radians
133  case ONI_STREAM_PROPERTY_MAX_VALUE: // int
134  case ONI_STREAM_PROPERTY_MIN_VALUE: // int
135  case ONI_STREAM_PROPERTY_STRIDE: // int
137  // camera
139  case ONI_STREAM_PROPERTY_AUTO_EXPOSURE: // OniBool
140  // xn
141  case XN_STREAM_PROPERTY_INPUT_FORMAT: // unsigned long long
142  case XN_STREAM_PROPERTY_CROPPING_MODE: // XnCroppingMode
144 
145  case ONI_STREAM_PROPERTY_VIDEO_MODE: // OniVideoMode*
146  if (dataSize != sizeof(OniVideoMode))
147  {
148  LogError("Unexpected size for ONI_STREAM_PROPERTY_VIDEO_MODE");
149  return ONI_STATUS_ERROR;
150  }
151  if (ONI_STATUS_OK != setVideoMode(*(static_cast<const OniVideoMode*>(data))))
153  raisePropertyChanged(propertyId, data, dataSize);
154  return ONI_STATUS_OK;
155 
156  case ONI_STREAM_PROPERTY_CROPPING: // OniCropping*
157  if (dataSize != sizeof(OniCropping))
158  {
159  LogError("Unexpected size for ONI_STREAM_PROPERTY_CROPPING");
160  return ONI_STATUS_ERROR;
161  }
162  cropping = *(static_cast<const OniCropping*>(data));
163  raisePropertyChanged(propertyId, data, dataSize);
164  return ONI_STATUS_OK;
165 
166  case ONI_STREAM_PROPERTY_MIRRORING: // OniBool
167  if (dataSize != sizeof(OniBool))
168  {
169  LogError("Unexpected size for ONI_STREAM_PROPERTY_MIRRORING");
170  return ONI_STATUS_ERROR;
171  }
172  mirroring = *(static_cast<const OniBool*>(data));
173  raisePropertyChanged(propertyId, data, dataSize);
174  return ONI_STATUS_OK;
175  }
176  }
177 
178 
179  /* todo : from StreamBase
180  virtual OniStatus convertDepthToColorCoordinates(StreamBase* colorStream, int depthX, int depthY, OniDepthPixel depthZ, int* pColorX, int* pColorY) { return ONI_STATUS_NOT_SUPPORTED; }
181  */
182  };
183 }
184 
185 
186 /* image video modes reference
187 
188 FREENECT_VIDEO_RGB = 0, //< Decompressed RGB mode (demosaicing done by libfreenect)
189 FREENECT_VIDEO_BAYER = 1, //< Bayer compressed mode (raw information from camera)
190 FREENECT_VIDEO_IR_8BIT = 2, //< 8-bit IR mode
191 FREENECT_VIDEO_IR_10BIT = 3, //< 10-bit IR mode
192 FREENECT_VIDEO_IR_10BIT_PACKED = 4, //< 10-bit packed IR mode
193 FREENECT_VIDEO_YUV_RGB = 5, //< YUV RGB mode
194 FREENECT_VIDEO_YUV_RAW = 6, //< YUV Raw mode
195 FREENECT_VIDEO_DUMMY = 2147483647, //< Dummy value to force enum to be 32 bits wide
196 
197 ONI_PIXEL_FORMAT_RGB888 = 200,
198 ONI_PIXEL_FORMAT_YUV422 = 201,
199 ONI_PIXEL_FORMAT_GRAY8 = 202,
200 ONI_PIXEL_FORMAT_GRAY16 = 203,
201 ONI_PIXEL_FORMAT_JPEG = 204,
202 */
virtual void populateFrame(void *data, OniFrame *frame) const =0
static void LogError(std::string error)
Definition: Utility.hpp:66
void raiseNewFrame(OniFrame *pFrame)
Definition: OniDriverAPI.h:92
virtual OniStatus setProperty(int propertyId, const void *data, int dataSize)
int resolutionY
Definition: OniCTypes.h:63
int OniBool
Definition: OniCTypes.h:28
int height
Definition: OniCTypes.h:105
uint64_t timestamp
Definition: OniCTypes.h:101
VideoStream(Freenect::FreenectDevice *device)
Definition: VideoStream.hpp:27
static const OniSensorType sensor_type
Definition: VideoStream.hpp:19
int frame
Definition: regview.c:72
int frameIndex
Definition: OniCTypes.h:102
StreamServices & getServices()
Definition: OniDriverAPI.h:95
OniSensorType
Definition: OniCEnums.h:38
void raisePropertyChanged(int propertyId, const void *data, int dataSize)
Definition: OniDriverAPI.h:93
OniVideoMode videoMode
Definition: OniCTypes.h:107
OniBool isPropertySupported(int propertyId)
Definition: VideoStream.hpp:66
Freenect::FreenectDevice * device
Definition: VideoStream.hpp:20
void buildFrame(void *data, uint32_t timestamp)
Definition: VideoStream.hpp:38
int resolutionX
Definition: OniCTypes.h:62
int width
Definition: OniCTypes.h:104
unsigned int uint32_t
OniStatus
Definition: OniCEnums.h:25
void releaseFrame(OniFrame *pFrame)
Definition: OniDriverAPI.h:59
virtual OniStatus getProperty(int propertyId, void *data, int *pDataSize)
Definition: VideoStream.hpp:79
virtual OniStatus setVideoMode(OniVideoMode requested_mode)=0


libfreenect
Author(s): Hector Martin, Josh Blake, Kyle Machulis, OpenKinect community
autogenerated on Thu Jun 6 2019 19:25:38