OptrisOptrisDocumentation

Documentation/OTC SDK/Optris.Sdk — C# API referencev12.0

SessionPlayer

public sealed class SessionPlayer : IDisposable

One session file, played back as one session: every source, on the clock they were recorded on, with seek applied to all of them.

A session is one file with one timeline. The presentation time on a frame already is session time: RecordingSession put it there, so alignment is a property of the file and not something playback has to reconstruct.

This also opens an ordinary single-camera recording, as a session of one source. That is deliberate: an application that has moved to this API does not need two code paths, and every file the single-camera recorder has ever written stays readable.

Read SessionPlayer.GetOutages(…) or SessionPlayer.GetPresentationAt(…) before drawing a source's frame. A camera that dropped out mid-session leaves a hole, and a viewer that holds the last frame across it shows a still picture of a scene nobody is watching, with nothing on it to say so.

Example

using var player = SessionPlayer.Open("dashboard.mkv");

player.OnFrame((source, frame) =>
    Console.WriteLine($"camera {source} max {frame.MaxTemperature:F1} C"));
player.OnPresentation(change =>
{
    if (change.Presentation == SessionPresentation.Disconnected)
    {
        Console.WriteLine($"camera {change.Source} lost: {change.Reason}");
    }
});

player.SeekTo(TimeSpan.FromSeconds(5));  // every source, one call
player.Play();

SessionPlayer: properties

public TimeSpan Duration { get; }

How long the session is: the end of whichever source ran longest.

  • Throws ObjectDisposedException: The player has been disposed.

The end of its last frame, not the position of it: that frame's own duration is included, so this is the length of the recording and not the timestamp of its last picture. It used to be the timestamp, which made a session report itself one frame period shorter than the same file opened as a ThermalCamera replay.

A source that ended early does not shorten the session. North running ten seconds beside a south that stopped at three is a ten-second session with a source that ended, and SessionPlayer.GetSourceInfo(…) and SessionPlayer.GetPresentationAt(…) are where that is reported.

Do not poll SessionPlayer.Position against this to find the end of a replay: the two are one frame period apart by design and never meet. Use SessionPlayer.IsAtEnd.

public bool IsAtEnd { get; }

Whether a non-looping session has handed over its last frame.

  • Throws ObjectDisposedException: The player has been disposed.

True once every source has delivered everything it holds and no wrap is coming. Ask this rather than comparing SessionPlayer.Position with SessionPlayer.Duration, which never become equal on a correct file.

False again after SessionPlayer.Play, SessionPlayer.Stop and SessionPlayer.SeekTo(…), so a transport that has run out can be restarted or dragged back. A looping session never reports an end, because it does not have one.

SessionPlayer.Play does not rewind: a session still sitting at the end reads end of file and says so again. Seek to zero to play it through a second time. That is the same behaviour as ThermalCamera.IsPlaybackAtEnd.

public bool IsLooping { set; }

Restart from the beginning at the end of the session.

  • Throws ObjectDisposedException: The player has been disposed.
public bool IsSession { get; }

Whether the file carries a session document.

  • Throws ObjectDisposedException: The player has been disposed.
public TimeSpan Position { get; }

Current position in session time.

  • Throws ObjectDisposedException: The player has been disposed.

The last delivered frame's session time. It is not how to see that a session has played out: SessionPlayer.Duration counts that frame's own length as well, so the two stand one frame period apart on a correct file and never meet. Use SessionPlayer.IsAtEnd.

public int SourceCount { get; }

How many sources the file holds.

  • Throws ObjectDisposedException: The player has been disposed.
public float Speed { set; }

Playback speed multiplier. 1.0 is real time.

  • Throws ArgumentOutOfRangeException: The value is not greater than zero.
  • Throws ObjectDisposedException: The player has been disposed.
public Nullable<DateTimeOffset> StartedAt { get; }

When the session started, as a date.

  • Throws ObjectDisposedException: The player has been disposed.
public SessionPlaybackStatistics Statistics { get; }

What this playback run has done.

  • Throws ObjectDisposedException: The player has been disposed.

SessionPlayer: methods

public void Dispose()

Stop playback and release the file.

Disposing twice is safe.

public IReadOnlyList<SessionOutage> GetOutages(int source)

Every outage this file recorded for one source, earliest first.

  • source: The source index.

Returns: Its outages.

  • Throws ArgumentOutOfRangeException: source is not one of this file's sources.
  • Throws ObjectDisposedException: The player has been disposed.

Available the moment the file is open, before anything is played, so an application can draw the holes onto its transport bar rather than discovering them by playing through. Empty for a source that was never away, and for a file written before outages were recorded.

public SessionPresentation GetPresentationAt(int source, TimeSpan at)

What a player should be showing for one source at a session time, without playing anything.

  • source: The source index.
  • at: The session time to ask about.

Returns: What to show.

  • Throws ArgumentOutOfRangeException: source is not one of this file's sources.
  • Throws ObjectDisposedException: The player has been disposed.

The scrubbing answer: an application that jumps the transport bar to 4 min 12 s asks this per source and knows what to draw before a single frame has been decoded. Consistent with what SessionPlayer.OnPresentation(…) reports while playing, because both read the same recorded spans.

public SessionSourceInfo GetSourceInfo(int source)

What the file says about one source, and what the scan found.

Returns: Its identity, size, span and frame count.

  • Throws ArgumentOutOfRangeException: source is not one of this file's sources.
  • Throws ObjectDisposedException: The player has been disposed.
public void OnColorFrame(ColorFrameHandler? handler)

Register the handler every visual source's pictures arrive on.

  • handler: What to call, or null to unregister.

  • Throws ObjectDisposedException: The player has been disposed.

Separate from SessionPlayer.OnFrame(…) rather than a variant of it, because the two carry different things and only one of them is a measurement. A consumer that wants only the radiometry registers only SessionPlayer.OnFrame(…) and never sees a visual track; one that draws the dashboard registers both and gets every source in session order across the two. Pass null to stop delivery.

public void OnFrame(Action<int, ThermalFrame>? handler)

Register the handler every thermal source's frames arrive on.

  • handler: What to call, or null to unregister.

  • Throws ObjectDisposedException: The player has been disposed.

Frames arrive in session order across sources, so a consumer that redraws a canvas on each one gets the dashboard as it was. The frame is valid for the duration of the call and disposed when it returns; clone it with ThermalFrame.Clone to keep one. The handler runs on the playback thread; do not dispose the player from it. Pass null to stop delivery.

public void OnPresentation(Action<SessionPresentationChange>? handler)

Be told what to show for a source, as playback crosses into and out of its outages.

  • handler: What to call, or null to unregister.

  • Throws ObjectDisposedException: The player has been disposed.

Fires when a source's presentation changes and not on every frame: once as playback enters a disconnection, once as it leaves, once when a track ends, and once per source at the start of playback and after every seek, so a consumer that joined mid-file is never left guessing.

A consumer cannot work this out for itself in time to be correct. A source that has gone quiet for 300 ms may be disconnected, may be a 3 Hz camera between frames, or may be mid-shutter, and the only honest way to distinguish them is to read what the recorder wrote down at the moment it knew, which is what this delivers. A viewer waiting for a timeout instead shows the last frame for the length of the timeout, every time, which is the failure it was trying to avoid.

The handler runs on the playback thread. Pass null to stop delivery.

public static SessionPlayer Open(string path)

Open a session recording.

  • path: The file to open.

Returns: The player.

  • Throws ArgumentException: path is null or empty.
  • Throws SdkIOException: The file cannot be opened or holds no video track.

The file is scanned once here, which is what fills in the per-source frame counts, spans, gaps and outages, so everything below is available before a frame is decoded.

public void Pause()

Stop advancing and hold the position.

  • Throws ObjectDisposedException: The player has been disposed.
public void Play()

Start playback on a background thread.

  • Throws ObjectDisposedException: The player has been disposed.
public void SeekTo(TimeSpan timestamp)

Move every source to a session timestamp.

  • timestamp: Where to go, in session time.

  • Throws ArgumentOutOfRangeException: timestamp is negative.

  • Throws ObjectDisposedException: The player has been disposed.

One call, all sources: that is what makes a session a session. Each source resumes at its first frame at or after timestamp, so a source that was mid-gap at that moment delivers nothing until its next real frame rather than back-filling one.

public void Stop()

Stop and rewind to the start of the session.

  • Throws ObjectDisposedException: The player has been disposed.