OptrisOptrisDocumentation

Documentation/OTC SDK/OTC SDK — C++ API referencev12.0

optris::sdk::rec::SessionPlayer

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

Why this is not N Players: Why this is not N Players Because a session is one file with one timeline. The presentation time on a frame already is session time -- SessionRecorder put it there -- so alignment is a property of the file and not something playback has to reconstruct. One demuxer feeding N decoders is therefore both simpler and exactly right, where N players sharing a clock would be N things to keep in step.

Thread safety: Thread safety The callback fires on the playback thread. Registration, transport and the getters are safe from any thread.

Example: Example cpp // Throws IoException if the file will not open. auto session = optris::sdk::rec::SessionPlayer::Open("dashboard.mkv"); session->SetFrameCallback( [](int source, const optris::sdk::ThermalFrame &frame, const optris::sdk::rec::Telemetry &telemetry) { // telemetry.timestamp_us is what the camera said about // itself. The session time this frame belongs to is the // player's position; see GetPositionUs(). std::println("camera {} max {:.1f} C", source, frame.GetMaxTemperature()); }); session->SeekToTimestamp(5'000'000); // every source, one call session->Play();

Public static functions

Open

static auto Open(const std::string &path) -> std::unique_ptr< SessionPlayer >

Open a session recording.

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.

The file is scanned once here, which is what fills in the per- source frame counts, spans and gaps.

Exceptions

Name Description
IoException when the file cannot be opened or is not a container FFmpeg understands.
SdkException when it carries nothing this SDK can replay.

Public functions

~SessionPlayer

~SessionPlayer()

SessionPlayer

SessionPlayer(const SessionPlayer &)=delete

operator=

SessionPlayer & operator=(const SessionPlayer &)=delete

GetSourceCount

auto GetSourceCount() const -> int

How many sources the file holds.

GetSourceInfo

auto GetSourceInfo(int source) const -> SessionSourceInfo

What the file says about one source, and what the scan found. Index out of range gives a zeroed struct.

IsSession

auto IsSession() const -> bool

Whether the file carries a session document.

False for a single-camera recording opened through this class, which still plays -- the names and the device identities are simply the ones the ordinary file metadata carries, or empty.

GetStartHostTimeUs

auto GetStartHostTimeUs() const -> uint64_t

When the session started, as a date: microseconds since the Unix epoch. Zero for a file that did not record one.

GetDurationUs

auto GetDurationUs() const -> uint64_t

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

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 Player.

A source that ended early does not shorten the session: 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. That south ended is reported by GetSourceInfo(south).last_frame_us and by GetPresentationAt(), which is where it belongs; it is not a statement about how long the session was.

This is not the container's own Duration, deliberately: This is not the container's own Duration, deliberately Matroska's Segment/Info/Duration is the end of the longest track, which Player reads and is right to. A session has tracks that are not pictures: each source has a telemetry track, and MarkSourceLost() and EndSource() write onto it at the moment they are called -- normally after that source's last frame, because a camera is noticed to be gone once it has stopped sending. Measured on a session whose cameras both stopped at 1 s and whose sources were ended at 4 s, the container reports 4 s for a file whose last picture ends at 1.033 s. So a session counts only its sources.

GetPositionUs

auto GetPositionUs() const -> int64_t

Current position in session microseconds.

It never runs backwards except where the caller sent it: It never runs backwards except where the caller sent it The last delivered frame's session time while playing, and a seek's target from the moment SeekToTimestamp() returns. It does not go back to the old position in between, so an application can drag a transport bar and read the position back to draw the thumb without the thumb snapping backwards for a frame period and then forward again. It used to be able to: the target and the delivered frame's time were published independently, and a frame decoded before the seek could overwrite the target after it.

Lock-free, so polling it from a redraw timer costs nothing.

IsAtEnd

auto IsAtEnd() const -> bool

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

Ask this rather than comparing the position with the: Ask this rather than comparing the position with the duration GetPositionUs() is the last delivered frame's session time; GetDurationUs() is where that frame ends. On a correct file the two differ by one frame period of the longest source and never meet, so position >= duration never becomes true. This is the same question IsAtEnd() answers for Player and it exists here for the same reason.

False again after Play(), Stop() and SeekToTimestamp(), 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.

Play() does not rewind: a session still sitting at the end reads end of file at once and reports the end again, often before the caller next looks. Seek to zero to play it through a second time. The playback thread has stopped by the time this turns true, so SeekToTimestamp() and Play() straight after it always replay.

SetFrameCallback

void SetFrameCallback(std::function< void(int, const optris::sdk::ThermalFrame &, const Telemetry &)> callback)

Register the callback every source's frames arrive on.

The first argument is the source index, matching GetSourceInfo(). Frames arrive in session order across sources, so a consumer that redraws a canvas on each one gets the dashboard as it was.

SetColorFrameCallback

void SetColorFrameCallback(std::function< void(int, const optris::sdk::RgbFrame &, const Telemetry &)> callback)

Register the callback a visual source's pictures arrive on.

Separate from SetFrameCallback() 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 the frame callback and never sees a visual track; one that draws the dashboard registers both and gets every source in session order across the two.

The pixels are packed RGB24, exactly as they were handed to SessionRecorder::WriteColorFrame(). The Telemetry carries the session time and nothing else -- a visual camera reports no radiometry and none is invented.

SetRegionStateCallback

void SetRegionStateCallback(std::function< void(int, const std::string &)> cb)

Register a callback for each frame's region record, as the recorder wrote it. Empty for a session made without regions.

SetSourcePresentationCallback

void SetSourcePresentationCallback(std::function< void(int, SessionSourcePresentation, uint64_t, const std::string &)> callback)

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

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. Delivered on the playback thread, like the frame callbacks.

Why this is not left to "no frames arrived": Why this is not left to "no frames arrived" Because a consumer cannot tell those apart 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 callback's arguments are the source index, what to show, the session microsecond the change happens at, and the reason the recorder recorded -- empty for SessionSourcePresentation::kPicture and for an outage recorded without one.

GetOutages

auto GetOutages(int source) const -> std::vector< SessionOutage >

Every outage this file recorded for one source, earliest first. Empty for a source that was never away, and for a file written before outages were recorded.

Available the moment the file is open, before anything is played: the open-time scan reads them. So an application can draw the holes onto its transport bar rather than discovering them by playing through.

GetPresentationAt

auto GetPresentationAt(int source, uint64_t session_us) const -> SessionSourcePresentation

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

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 SetSourcePresentationCallback() reports while playing, because both read the same recorded spans.

Play

void Play()

Start playback on a background thread.

Pause

void Pause()

Stop advancing and join the playback thread, holding the position.

Stop

void Stop()

Stop and rewind to the start of the session.

SeekToTimestamp

void SeekToTimestamp(uint64_t timestamp_us)

Move every source to a session timestamp, in microseconds.

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

While playing, this is a request rather than an act: While playing, this is a request rather than an act A seek tears down the demuxer's position, every decoder's buffers and the queue of frames waiting to be handed over, all of which the playback thread is using. So a seek asked for while playback is running is carried out by the playback thread, at the top of its next pass, which is the only place it is safe.

How long that takes is one frame still being handed over, not "microseconds" as this said before it was measured: the pass paces itself to the file's own rate, so the wait is up to one frame period divided by the speed. Use IsSeekPending() rather than a figure.

GetPositionUs() reports the target immediately either way, and keeps reporting at least the target from then on. A frame decoded before the seek is discarded rather than delivered and never publishes its own position over the target. So the two facts a caller has are: where the transport is, straight away, and whether the picture has caught up, from IsSeekPending().

IsSeekPending

auto IsSeekPending() const -> bool

Whether a seek asked for while playing has not happened yet.

False the moment SeekToTimestamp() returns when playback is stopped, and false again within one pass of the playback loop when it is running. It exists because "the slider is at 7 s" and "the picture is from 7 s" are two different facts for the microseconds in between, and an application that draws a measurement beside a frame should not attribute a frame from before the seek to the position after it.

When this goes false, every frame still to be delivered is from at or after the seek target: the seek discards what was in flight before it clears this.

SetSpeed

void SetSpeed(float speed)

Playback speed multiplier. 1.0 is real time.

SetLoop

void SetLoop(bool loop)

Restart from the beginning at the end of the session.

GetAttachment

auto GetAttachment(const std::string &name) const -> std::optional< std::string >

Read an attachment by filename, e.g. kSessionMetadataName.

GetStatistics

auto GetStatistics() const -> SessionPlaybackStats

What this playback run has done. See SessionPlaybackStats.