OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ImagingComponent.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_ImagingComponent_h_GUID_BA26C922_01FD_43B3_8EB7_A9AB2777CEBC
26 #define INCLUDED_ImagingComponent_h_GUID_BA26C922_01FD_43B3_8EB7_A9AB2777CEBC
27 
28 // Internal Includes
29 #include <osvr/Common/Export.h>
36 
37 // Library/third-party includes
38 #include <vrpn_BaseClass.h>
39 
40 // Standard includes
41 // - none
42 
43 namespace osvr {
44 namespace common {
45  typedef shared_ptr<OSVR_ImageBufferElement> ImageBufferPtr;
46  struct ImageData {
47  OSVR_ChannelCount sensor;
48  OSVR_ImagingMetadata metadata;
49  ImageBufferPtr buffer;
50  };
51  namespace messages {
52  class ImageRegion : public MessageRegistration<ImageRegion> {
53  public:
55 
56  static const char *identifier();
57  };
58 #ifdef OSVR_COMMON_IN_PROCESS_IMAGING
59  class ImagePlacedInProcessMemory
60  : public MessageRegistration<ImagePlacedInProcessMemory> {
61  public:
62  class MessageSerialization;
63  static const char *identifier();
64  };
65 #endif
67  : public MessageRegistration<ImagePlacedInSharedMemory> {
68  public:
70  static const char *identifier();
71  };
72  } // namespace messages
73 
76  public:
81  static OSVR_COMMON_EXPORT shared_ptr<ImagingComponent>
82  create(OSVR_ChannelCount numSensor = 0);
83 
86 
90 
91 #ifdef OSVR_COMMON_IN_PROCESS_IMAGING
92  messages::ImagePlacedInProcessMemory imagePlacedInProcessMemory;
95 #endif
96 
97  OSVR_COMMON_EXPORT void sendImageData(
98  OSVR_ImagingMetadata metadata, OSVR_ImageBufferElement *imageData,
99  OSVR_ChannelCount sensor, OSVR_TimeValue const &timestamp);
100 
101  typedef std::function<void(ImageData const &,
102  util::time::TimeValue const &)> ImageHandler;
103  OSVR_COMMON_EXPORT void registerImageHandler(ImageHandler cb);
104 
105  private:
107  virtual void m_parentSet();
108 
110  bool m_sendImageDataViaSharedMemory(OSVR_ImagingMetadata metadata,
111  OSVR_ImageBufferElement *imageData,
112  OSVR_ChannelCount sensor,
113  OSVR_TimeValue const &timestamp);
114 
116  bool m_sendImageDataOnTheWire(OSVR_ImagingMetadata metadata,
117  OSVR_ImageBufferElement *imageData,
118  OSVR_ChannelCount sensor,
119  OSVR_TimeValue const &timestamp);
120 
121 #ifdef OSVR_COMMON_IN_PROCESS_IMAGING
122  bool m_sendImageDataViaInProcessMemory(OSVR_ImagingMetadata metadata,
124  OSVR_ImageBufferElement *imageData,
125  OSVR_ChannelCount sensor,
126  OSVR_TimeValue const &timestamp);
127 #endif
128 
129  static int VRPN_CALLBACK
130  m_handleImageRegion(void *userdata, vrpn_HANDLERPARAM p);
131 
132  static int VRPN_CALLBACK
133  m_handleImagePlacedInSharedMemory(void *userdata, vrpn_HANDLERPARAM p);
134 
135 #ifdef OSVR_COMMON_IN_PROCESS_IMAGING
136  static int VRPN_CALLBACK
137  m_handleImagePlacedInProcessMemory(void *userdata, vrpn_HANDLERPARAM p);
138 #endif
139 
140  void m_checkFirst(OSVR_ImagingMetadata const &metadata);
141  void m_growShmVecIfRequired(OSVR_ChannelCount sensor);
142 
143  OSVR_ChannelCount m_numSensor;
144  std::vector<ImageHandler> m_cb;
145  bool m_gotOne;
147  std::vector<IPCRingBufferPtr> m_shmBuf;
148  };
149 } // namespace common
150 } // namespace osvr
151 
152 #endif // INCLUDED_ImagingComponent_h_GUID_BA26C922_01FD_43B3_8EB7_A9AB2777CEBC
uint32_t OSVR_ChannelCount
The integer type specifying a number of channels/sensors or a channel/sensor index.
Definition: ChannelCountC.h:51
static shared_ptr< ImagingComponent > create(OSVR_ChannelCount numSensor=0)
Factory method.
CRTP class template wrapping message-specific data and/or logic.
Generated header describing imaging component config.
Automatically-generated export header - do not edit!
messages::ImageRegion imageRegion
Message from server to client, containing some image data.
BaseDevice component.
messages::ImagePlacedInSharedMemory imagePlacedInSharedMemory
Message from server to client, notifying of image data in the shared memory ring buffer.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
unsigned char OSVR_ImageBufferElement
Type for raw buffer access to image data.