OSVR-Core  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Imaging.c
Go to the documentation of this file.
1 
11 /*
12 // Copyright 2015 Sensics, Inc.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "License");
15 // you may not use this file except in compliance with the License.
16 // You may obtain a copy of the License at
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 // See the License for the specific language governing permissions and
24 // limitations under the License.
25 */
26 
27 /* Internal Includes */
32 
33 /* Standard includes */
34 #include <stdio.h>
35 
36 unsigned int reportNumber = 0;
37 
38 void imagingCallback(void *userdata, const OSVR_TimeValue *timestamp,
39  const OSVR_ImagingReport *report) {
40  /* @todo implement a C equivalent to the C++ empty() check here. */
41  OSVR_ClientContext* ctx = (OSVR_ClientContext*)userdata;
42 
43  /* The first time, let's print some info. */
44  if (reportNumber == 0) {
45  printf("Got first report: image is %d width and %d height.\n",
46  report->state.metadata.width, report->state.metadata.height);
47  }
48  else {
49  printf("Got report number %d\n", reportNumber);
50  }
51 
52  reportNumber++;
53  if (OSVR_RETURN_SUCCESS != osvrClientFreeImage(*ctx, report->state.data)) {
54  printf("Error, osvrClientFreeImage call failed.\n");
55  }
56 }
57 
58 int main() {
59  OSVR_ClientContext ctx =
60  osvrClientInit("com.osvr.exampleclients.Imaging", 0);
61  if(!ctx) {
62  printf("Error, could not initialize client context. The server may not be running.\n");
63  return -1;
64  }
65 
66  OSVR_ClientInterface camera = NULL;
67  if(OSVR_RETURN_SUCCESS != osvrClientGetInterface(ctx, "/camera", &camera)) {
68  printf("Error, could not get the camera interface at /camera.\n");
69  return -1;
70  }
71 
72  /* Register the imaging callback. */
74  printf("Error, could not register image callback.");
75  return -1;
76  }
77 
78  /* Pretend that this is your application's mainloop. */
79  int i;
80  for (i = 0; i < 1000000; ++i) {
82  printf("Error, while updating the client context.");
83  }
84  }
85 
86  osvrClientShutdown(ctx);
87  printf("Library shut down, exiting.\n");
88 }
Header.
OSVR_ReturnCode osvrClientGetInterface(OSVR_ClientContext ctx, const char path[], OSVR_ClientInterface *iface)
Get the interface associated with the given path.
OSVR_EXTERN_C_BEGIN OSVR_ReturnCode osvrClientFreeImage(OSVR_ClientContext ctx, OSVR_ImageBufferElement *buf)
Free an image buffer returned from a callback.
OSVR_ClientContext osvrClientInit(const char applicationIdentifier[], uint32_t flags=0)
Initialize the library.
OSVR_ReturnCode osvrClientShutdown(OSVR_ClientContext ctx)
Shutdown the library.
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:45
struct OSVR_ClientContextObject * OSVR_ClientContext
Opaque handle that should be retained by your application. You need only and exactly one...
OSVR_ReturnCode osvrClientUpdate(OSVR_ClientContext ctx)
Updates the state of the context - call regularly in your mainloop.
Header.
void imagingCallback(void *userdata, osvr::util::time::TimeValue const &timestamp, osvr::clientkit::ImagingReport report)
Definition: Imaging.cpp:45
struct OSVR_ClientInterfaceObject * OSVR_ClientInterface
Opaque handle to an interface used for registering callbacks and getting status.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
OSVR_ReturnCode osvrRegisterImagingCallback(OSVR_ClientInterface iface, OSVR_ImagingCallback cb, void *userdata)
Register a callback for Imaging reports on an interface.
Header.