To get started with eye tracking in your application you must first grab the StreamEngine library. Download the archive containing the library and all necessary header files, then follow the steps below to find out how to integrate StreamEngine in your application.

Makefile project

For those that are using a makefile based build systems, there is an easy way to integrate StreamEngine into your application:

  • Setup new VS Solution (Console App .NET Framework)
  • Create a new folder called ‘tobii’ in the project directory
  • Copy into the tobii folder the following directories from the Stream Engine ZIP; bindings, include, lib
  • Within the VS Solution Explorer, make sure these directories are ‘included in project’ (You may need to select ‘view all files’ button)
  • Paste into Program.cs the C# Sample Code found @ https://developer.tobii.com/product-integration/stream-engine/getting-started/
  • Link your application with tobii_stream_engine dynamic library.
  • Modify Tobii.StreamEngine.Interop.cs, Line 23:  public const string stream_engine_dll = “tobii\\lib\\tobii\\tobii_stream_engine”;
  • Comment out Tobii.StreamEngine.Interop.cs, Lines 487 & 488//[DllImport(stream_engine_dll, CallingConvention = CallingConvention.Cdecl, EntryPoint = “tobii_calibration_stimulus_points_get”)]//public static extern tobii_error_t tobii_calibration_stimulus_points_get(IntPtr device, out tobii_calibration_stimulus_points_t stimulus_points);
  • In VS Solution Explorer, find the tobii_stream_engine.dll and set copy to output directory as “Copy Always”
  • Set Build Target to x64

Now you are all set to start using StreamEngine in your application. Check out the super simple sample bellow or move on to our more advanced best practices samples and Api documentation.

Super simple C# .NET application


using System;
using System.Collections.Generic;
using System.Diagnostics;
using Tobii.StreamEngine;

namespace Tobii.StreamEngine.Sample
{
    public static class StreamSample
    {
        private static void OnGazePoint(ref tobii_gaze_point_t gazePoint, IntPtr userData) 
        {
            // Check that the data is valid before using it
            if(gazePoint.validity == tobii_validity_t.TOBII_VALIDITY_VALID) 
            {
                Console.WriteLine($"Gaze point: {gazePoint.position.x}, {gazePoint.position.y}");
            }
        }

        public static void Main()
        {
            // Create API context
            IntPtr apiContext;
            tobii_error_t result = Interop.tobii_api_create(out apiContext, null);
            Debug.Assert(result == tobii_error_t.TOBII_ERROR_NO_ERROR);

            // Enumerate devices to find connected eye trackers
            List<string> urls;
            result = Interop.tobii_enumerate_local_device_urls(apiContext, out urls);
            Debug.Assert(result == tobii_error_t.TOBII_ERROR_NO_ERROR);
            if(urls.Count == 0)
            {
                Console.WriteLine("Error: No device found");
                return;
            }

            // Connect to the first tracker found
            IntPtr deviceContext;
            result = Interop.tobii_device_create(apiContext, urls[0], Interop.tobii_field_of_use_t.TOBII_FIELD_OF_USE_STORE_OR_TRANSFER_FALSE, out deviceContext);
            Debug.Assert(result == tobii_error_t.TOBII_ERROR_NO_ERROR);

            // Subscribe to gaze data
            result = Interop.tobii_gaze_point_subscribe(deviceContext, OnGazePoint);
            Debug.Assert(result == tobii_error_t.TOBII_ERROR_NO_ERROR);

            // This sample will collect 1000 gaze points
            for ( int i=0; i<1000; i++ )
            {
                // Optionally block this thread until data is available. Especially useful if running in a separate thread.
                Interop.tobii_wait_for_callbacks(new [] { deviceContext });
                Debug.Assert(result == tobii_error_t.TOBII_ERROR_NO_ERROR || result == tobii_error_t.TOBII_ERROR_TIMED_OUT);
                
                // Process callbacks on this thread if data is available
                Interop.tobii_device_process_callbacks(deviceContext);
                Debug.Assert(result == tobii_error_t.TOBII_ERROR_NO_ERROR);
            }

            // Cleanup
            result = Interop.tobii_gaze_point_unsubscribe(deviceContext);
            Debug.Assert(result == tobii_error_t.TOBII_ERROR_NO_ERROR);
            result = Interop.tobii_device_destroy(deviceContext);
            Debug.Assert(result == tobii_error_t.TOBII_ERROR_NO_ERROR);
            result = Interop.tobii_api_destroy(apiContext);
            Debug.Assert(result == tobii_error_t.TOBII_ERROR_NO_ERROR);
        }
    }
}

Super simple C++ Application


#include <tobii/tobii.h>
#include <tobii/tobii_streams.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>

void gaze_point_callback( tobii_gaze_point_t const* gaze_point, void* /* user_data */)
{
    // Check that the data is valid before using it
    if( gaze_point->validity == TOBII_VALIDITY_VALID )
        printf( "Gaze point: %f, %f\n",
            gaze_point->position_xy[ 0 ],
            gaze_point->position_xy[ 1 ] );
}

void url_receiver( char const* url, void* user_data )
{
    char* buffer = (char*)user_data;
    if( *buffer != '\0' ) return; // only keep first value

    if( strlen( url ) < 256 )
        strcpy( buffer, url );
}

int main()
{
    // Create API
    tobii_api_t* api = NULL;
    tobii_error_t result = tobii_api_create( &api, NULL, NULL );
    assert( result == TOBII_ERROR_NO_ERROR );

    // Enumerate devices to find connected eye trackers, keep the first
    char url[ 256 ] = { 0 };
    result = tobii_enumerate_local_device_urls( api, url_receiver, url );
    assert( result == TOBII_ERROR_NO_ERROR );
    if(*url == '\0')
    {
        printf("Error: No device found\n");
        return 1;
    }

    // Connect to the first tracker found
    tobii_device_t* device = NULL;
    result = tobii_device_create( api, url, TOBII_FIELD_OF_USE_INTERACTIVE, &device );
    assert( result == TOBII_ERROR_NO_ERROR );

    // Subscribe to gaze data
    result = tobii_gaze_point_subscribe( device, gaze_point_callback, 0 );
    assert( result == TOBII_ERROR_NO_ERROR );

    // This sample will collect 1000 gaze points
    for( int i=0; i<1000; i++ )
    {
        // Optionally block this thread until data is available. Especially useful if running in a separate thread.
        result = tobii_wait_for_callbacks( 1, &device );
        assert( result == TOBII_ERROR_NO_ERROR || result == TOBII_ERROR_TIMED_OUT );

        // Process callbacks on this thread if data is available
        result = tobii_device_process_callbacks( device );
        assert( result == TOBII_ERROR_NO_ERROR );
    }

    // Cleanup
    result = tobii_gaze_point_unsubscribe( device );
    assert( result == TOBII_ERROR_NO_ERROR );
    result = tobii_device_destroy( device );
    assert( result == TOBII_ERROR_NO_ERROR );
    result = tobii_api_destroy( api );
    assert( result == TOBII_ERROR_NO_ERROR );
    return 0;
}

Eye Tracking Data Transparency Policy

This policy applies to solutions that store or transfer Tobii eye tracking data, presence or position data, regardless of the purpose for the storing or transferring. End-users care about their data integrity and privacy. Therefore, as a vendor you must gain end-users’ trust regarding what you do with the end users’s eye tracking data. Being transparent is a good starting point in gaining trust and that is why we created the Tobii Eye Tracking Data Transparency policy.

Linux and MacOS

  • Our gaming eye tracker, Tobii Eye Tracker 5, only supports Windows. Software development kits for the 5 are only available for Windows.
  • If you want to develop a product integrating Tobii Eye Tracking we have other solutions such as the Tobii Eye Tracker 5L, and integration platforms that also support Linux and MacOS. If you are interested in integrating eye tracking in your product please Contact Tobii.