Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Util_LatencyTest2.cpp
Go to the documentation of this file.
1 /************************************************************************************
2 
3 Filename : Util_LatencyTest2.cpp
4 Content : Wraps the lower level LatencyTester interface for DK2 and adds functionality.
5 Created : March 10, 2014
6 Authors : Volga Aksoy
7 
8 Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
9 
10 Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
11 you may not use the Oculus VR Rift SDK except in compliance with the License,
12 which is provided at the time of installation or download, or which
13 otherwise accompanies this software in either electronic or hard copy form.
14 
15 You may obtain a copy of the License at
16 
17 http://www.oculusvr.com/licenses/LICENSE-3.1
18 
19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
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 *************************************************************************************/
26 
27 #include "Util_LatencyTest2.h"
28 
29 #include "../OVR_CAPI.h"
30 #include "../Kernel/OVR_Log.h"
31 #include "../Kernel/OVR_Timer.h"
32 
33 
34 namespace OVR { namespace Util {
35 
36 //-------------------------------------------------------------------------------------
37 // ***** LatencyTest2
38 
40  : Handler(getThis())
41  , TestActive(false)
42  , StartTiming(-1)
43  , LatencyMeasuredInSeconds(-1)
44  , LastPixelReadMsg(NULL)
45  , RenderColorValue(0)
46  , NumMsgsBeforeSettle(0)
47  , NumTestsSuccessful(0)
48 {
49  if (device != NULL)
50  {
51  SetSensorDevice(device);
52  }
53 }
54 
56 {
57  HmdDevice = NULL;
59 
61 }
62 
64 {
65  Lock::Locker devLocker(&TesterLock);
66 
67  // Enable/Disable pixel read from HMD
68  if (device != HmdDevice)
69  {
71 
72  HmdDevice = device;
73 
74  if (HmdDevice != NULL)
75  {
76  HmdDevice->AddMessageHandler(&Handler);
77  }
78  }
79 
80  return true;
81 }
82 
84 {
85  Lock::Locker devLocker(&TesterLock);
86 
87  if (device != LatencyTesterDev)
88  {
89  LatencyTesterDev = device;
90  if (LatencyTesterDev != NULL)
91  {
92  // Set display to initial (3 dashes).
93  LatencyTestDisplay ltd(2, 0x40400040);
94  LatencyTesterDev->SetDisplay(ltd);
95  }
96  }
97 
98  return true;
99 }
100 
101 void LatencyTest2::BeginTest(double startTime)
102 {
103  Lock::Locker devLocker(&TesterLock);
104 
105  if (!TestActive)
106  {
107  TestActive = true;
109 
110  // Go to next pixel value
111  //RenderColorValue = (RenderColorValue == 0) ? 255 : 0;
114 
115  if (startTime > 0.0)
116  StartTiming = startTime;
117  else
119 
120  }
121 }
122 
124 {
125  Lock::Locker devLocker(&TesterLock);
126 
127  // Hold onto the last message as we will use this when we start a new test
128  LastPixelReadMsg = msg;
129 
130  // If color readback index is valid, store it in the lock-less queue.
131  int readbackIndex = 0;
132  if (FrameTimeRecord::ColorToReadbackIndex(&readbackIndex, msg.PixelReadValue))
133  {
134  RecentFrameSet.AddValue(readbackIndex, msg.FrameTimeSeconds);
135  LockessRecords.SetState(RecentFrameSet);
136  }
137 
139 
140  if (TestActive)
141  {
142  int pixelValueDiff = RenderColorValue - LastPixelReadMsg.PixelReadValue;
143  int rawTimeDiff = LastPixelReadMsg.RawFrameTime - RawStartTiming;
144 
145  if (pixelValueDiff < LT2_PixelTestThreshold && pixelValueDiff > -LT2_PixelTestThreshold)
146  {
147  TestActive = false;
148 
150  RawLatencyMeasured = rawTimeDiff;
151  //LatencyMeasuredInSeconds = RawLatencyMeasured / 1000000.0;
152 
153  if(LatencyTesterDev && (NumTestsSuccessful % 5) == 0)
154  {
155  int displayNum = (int)(RawLatencyMeasured / 100.0);
156  //int displayNum = NumMsgsBeforeSettle;
157  //int displayNum = (int)(LatencyMeasuredInSeconds * 1000.0);
158  LatencyTestDisplay ltd(1, displayNum);
159  LatencyTesterDev->SetDisplay(ltd);
160  }
161 
163  }
164  else if (TestActive && (rawTimeDiff / 1000) > LT2_TimeoutWaitingForColorDetected)
165  {
166  TestActive = false;
168  }
169  }
170 }
171 
173 {
175 }
176 
178 {
179  if(msg.Type == Message_PixelRead)
180  pLatencyTestUtil->handleMessage(static_cast<const MessagePixelRead&>(msg));
181 }
182 
184 {
185  Lock::Locker devLocker(&TesterLock);
186  colorToDisplay = Color(RenderColorValue, RenderColorValue, RenderColorValue, 255);
187 
188  return TestActive;
189 }
190 
191 }} // namespace OVR::Util
Ptr< SensorDevice > HmdDevice
#define NULL
OVR_EXPORT double ovr_GetTimeInSeconds()
Definition: OVR_CAPI.cpp:182
virtual void OnMessage(const Message &msg)
Ptr< LatencyTestDevice > LatencyTesterDev
MessagePixelRead LastPixelReadMsg
void BeginTest(double startTime=-1.0f)
MessageType Type
static bool ColorToReadbackIndex(int *readbackIndex, unsigned char color)
LocklessUpdater< FrameTimeRecordSet > LockessRecords
void AddValue(int readValue, double timeSeconds)
LatencyTest2(SensorDevice *device=NULL)
FrameTimeRecordSet RecentFrameSet
bool DisplayScreenColor(Color &colorToDisplay)
bool SetDisplayDevice(LatencyTestDevice *device)
void handleMessage(const MessagePixelRead &msg)
bool SetSensorDevice(SensorDevice *device)