Util_LatencyTest.h
Go to the documentation of this file.
00001 /************************************************************************************
00002 
00003 PublicHeader:   OVR.h
00004 Filename    :   Util_LatencyTest.h
00005 Content     :   Wraps the lower level LatencyTesterDevice and adds functionality.
00006 Created     :   February 14, 2013
00007 Authors     :   Lee Cooper
00008 
00009 Copyright   :   Copyright 2013 Oculus VR, Inc. All Rights reserved.
00010 
00011 Use of this software is subject to the terms of the Oculus license
00012 agreement provided at the time of installation or download, or which
00013 otherwise accompanies this software in either electronic or hard copy form.
00014 
00015 *************************************************************************************/
00016 
00017 #ifndef OVR_Util_LatencyTest_h
00018 #define OVR_Util_LatencyTest_h
00019 
00020 #include "../OVR_Device.h"
00021 
00022 #include "../Kernel/OVR_String.h"
00023 #include "../Kernel/OVR_List.h"
00024 
00025 namespace OVR { namespace Util {
00026 
00027 
00028 //-------------------------------------------------------------------------------------
00029 // ***** LatencyTest
00030 //
00031 // LatencyTest utility class wraps the low level LatencyTestDevice and manages the scheduling
00032 // of a latency test. A single test is composed of a series of individual latency measurements
00033 // which are used to derive min, max, and an average latency value.
00034 //
00035 // Developers are required to call the following methods:
00036 //      SetDevice - Sets the LatencyTestDevice to be used for the tests.
00037 //      ProcessInputs - This should be called at the same place in the code where the game engine
00038 //                      reads the headset orientation from LibOVR (typically done by calling
00039 //                      'GetOrientation' on the SensorFusion object). Calling this at the right time
00040 //                      enables us to measure the same latency that occurs for headset orientation
00041 //                      changes.
00042 //      DisplayScreenColor -    The latency tester works by sensing the color of the pixels directly
00043 //                              beneath it. The color of these pixels can be set by drawing a small
00044 //                              quad at the end of the rendering stage. The quad should be small
00045 //                              such that it doesn't significantly impact the rendering of the scene,
00046 //                              but large enough to be 'seen' by the sensor. See the SDK
00047 //                              documentation for more information.
00048 //              GetResultsString -      Call this to get a string containing the most recent results.
00049 //                                                      If the string has already been gotten then NULL will be returned.
00050 //                                                      The string pointer will remain valid until the next time this 
00051 //                                                      method is called.
00052 //
00053 
00054 class LatencyTest : public NewOverrideBase
00055 {
00056 public:
00057     LatencyTest(LatencyTestDevice* device = NULL);
00058     ~LatencyTest();
00059     
00060     // Set the Latency Tester device that we'll use to send commands to and receive
00061     // notification messages from.
00062     bool        SetDevice(LatencyTestDevice* device);
00063 
00064     // Returns true if this LatencyTestUtil has a Latency Tester device.
00065     bool        HasDevice() const
00066     { return Handler.IsHandlerInstalled(); }
00067 
00068     void        ProcessInputs();
00069     bool        DisplayScreenColor(Color& colorToDisplay);
00070         const char*     GetResultsString();
00071 
00072     // Begin test. Equivalent to pressing the button on the latency tester.
00073     void BeginTest();
00074 
00075 private:
00076     LatencyTest* getThis()  { return this; }
00077 
00078     enum LatencyTestMessageType
00079     {
00080         LatencyTest_None,
00081         LatencyTest_Timer,
00082         LatencyTest_ProcessInputs,
00083     };
00084     
00085     UInt32 getRandomComponent(UInt32 range);
00086     void handleMessage(const Message& msg, LatencyTestMessageType latencyTestMessage = LatencyTest_None);
00087     void reset();
00088     void setTimer(UInt32 timeMilliS);
00089     void clearTimer();
00090 
00091     class LatencyTestHandler : public MessageHandler
00092     {
00093         LatencyTest*    pLatencyTestUtil;
00094     public:
00095         LatencyTestHandler(LatencyTest* latencyTester) : pLatencyTestUtil(latencyTester) { }
00096         ~LatencyTestHandler();
00097 
00098         virtual void OnMessage(const Message& msg);
00099     };
00100 
00101     bool areResultsComplete();
00102     void processResults();
00103     void updateForTimeouts();
00104 
00105     Ptr<LatencyTestDevice>      Device;
00106     LatencyTestHandler          Handler;
00107 
00108     enum TesterState
00109     {
00110         State_WaitingForButton,
00111         State_WaitingForSettlePreCalibrationColorBlack,
00112         State_WaitingForSettlePostCalibrationColorBlack,
00113         State_WaitingForSettlePreCalibrationColorWhite,
00114         State_WaitingForSettlePostCalibrationColorWhite,
00115         State_WaitingToTakeMeasurement,
00116         State_WaitingForTestStarted,
00117         State_WaitingForColorDetected,
00118         State_WaitingForSettlePostMeasurement
00119     };
00120     TesterState                 State;
00121 
00122     bool                        HaveOldTime;
00123     UInt32                      OldTime;
00124     UInt32                      ActiveTimerMilliS;
00125 
00126     Color                       RenderColor;
00127 
00128     struct MeasurementResult : public ListNode<MeasurementResult>, public NewOverrideBase
00129     {
00130         MeasurementResult()
00131          :  DeviceMeasuredElapsedMilliS(0),
00132             TimedOutWaitingForTestStarted(false),
00133             TimedOutWaitingForColorDetected(false),
00134             StartTestTicksMicroS(0),
00135             TestStartedTicksMicroS(0)
00136         {}
00137 
00138         Color                   TargetColor;
00139 
00140         UInt32                  DeviceMeasuredElapsedMilliS;
00141 
00142         bool                    TimedOutWaitingForTestStarted;
00143         bool                    TimedOutWaitingForColorDetected;
00144 
00145         UInt64                  StartTestTicksMicroS;
00146         UInt64                  TestStartedTicksMicroS;
00147     };
00148 
00149     List<MeasurementResult>     Results;
00150     void clearMeasurementResults();
00151 
00152     MeasurementResult*          getActiveResult();
00153 
00154     StringBuffer                            ResultsString;
00155         String                                      ReturnedResultString;
00156 };
00157 
00158 }} // namespace OVR::Util
00159 
00160 #endif // OVR_Util_LatencyTest_h


oculus_sdk
Author(s):
autogenerated on Mon Oct 6 2014 03:01:19