Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions examples/ShowPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <ola/base/SysExits.h>
#include <ola/client/ClientWrapper.h>
#include <ola/client/OlaClient.h>
#include <climits>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think #include <stdint.h> should provide INT64_MAX too and we've already used that successfully on lots of platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually pulled in <climits> because we needed UINT_MAX, and that's not something that <stdint.h> is specified to provide.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though in hindsight it's only needed for clamping, so I should have guarded that with an #if... #endif too....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we use #include <limits.h> for that (I think) in

UIntValidator(0, UINT_MAX),

#include <fstream>
#include <iostream>
#include <string>
Expand Down Expand Up @@ -216,15 +217,18 @@ ShowLoader::State ShowPlayer::SeekTo(uint64_t seek_time) {
break;
}
}
uint64_t timeout = playhead_time - seek_time;
m_playback_pos = playhead_time;
m_clock.CurrentMonotonicTime(&m_start_ts);
m_start_playback_pos = m_playback_pos - timeout;

// Send data in the state it would be in at the given time
map<unsigned int, ShowEntry>::iterator entry_it;
for (entry_it = entries.begin(); entry_it != entries.end(); ++entry_it) {
SendFrame(entry_it->second);
}
// Adjust the timeout to handle landing in the middle of the entry's timeout
RegisterNextTimeout(playhead_time-seek_time);
RegisterNextTimeout(timeout);

return ShowLoader::OK;
}
Expand Down Expand Up @@ -270,8 +274,35 @@ void ShowPlayer::SendEntry(const ShowEntry &entry) {
SendFrame(entry);
m_playback_pos += entry.next_wait;

unsigned int timeout = entry.next_wait;
if (!m_simulate) {
// Using int64_t for target_delta here because we have to lose 1 bit anyway
// as InMilliSeconds() returns a signed 64-bit integer.
ola::TimeStamp now;
m_clock.CurrentMonotonicTime(&now);
int64_t target_delta = m_playback_pos - m_start_playback_pos;
int64_t current_delta = (now - m_start_ts).InMilliSeconds();
int64_t delay = target_delta - current_delta;
if (delay < 0) {
OLA_WARN << "Frame at line " << m_loader.GetCurrentLineNumber()
<< " was meant to have completed " << -delay << " ms ago."
<< " System too slow?";
delay = 0;
}

#if UINT_MAX < INT64_MAX
if (delay > UINT_MAX) {
OLA_WARN << "Calculated delay of " << delay << " ms"
<< " exceeded maximum delay of " << UINT_MAX << " ms."
<< " Clamping to maximum.";
delay = UINT_MAX;
}
#endif

timeout = delay;
}
// Set when next to send data
RegisterNextTimeout(entry.next_wait);
RegisterNextTimeout(timeout);
}


Expand Down
4 changes: 4 additions & 0 deletions examples/ShowPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Copyright (C) 2011 Simon Newton
*/

#include <ola/Clock.h>
#include <ola/DmxBuffer.h>
#include <ola/client/ClientWrapper.h>

Expand Down Expand Up @@ -89,6 +90,9 @@ class ShowPlayer {
uint64_t m_run_time;
std::map<unsigned int, uint64_t> m_frame_count;
bool m_simulate;
ola::Clock m_clock;
ola::TimeStamp m_start_ts;
uint64_t m_start_playback_pos;

/** Used for tracking simulation progress */
typedef enum {
Expand Down
19 changes: 12 additions & 7 deletions examples/ShowSaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ using std::endl;
const char ShowSaver::OLA_SHOW_HEADER[] = "OLA Show";

ShowSaver::ShowSaver(const string &filename)
: m_filename(filename) {
: m_filename(filename),
m_saved_elapsed_ms(0) {
}


Expand Down Expand Up @@ -84,13 +85,17 @@ bool ShowSaver::NewFrame(const ola::TimeStamp &arrival_time,
unsigned int universe,
const ola::DmxBuffer &data) {
// TODO(simon): add much better error handling here
if (m_last_frame.IsSet()) {
// this is not the first frame so write the delay in ms
const ola::TimeInterval delta = arrival_time - m_last_frame;

m_show_file << delta.InMilliSeconds() << endl;
if (m_first_frame.IsSet()) {
const ola::TimeInterval delta = arrival_time - m_first_frame;
int64_t saved_delta_ms = (delta.InMilliSeconds() - m_saved_elapsed_ms);
m_saved_elapsed_ms += saved_delta_ms;

m_show_file << saved_delta_ms << endl;
} else {
m_first_frame = arrival_time;
}
m_last_frame = arrival_time;

m_show_file << universe << " " << data.ToString() << endl;

return true;
}
3 changes: 2 additions & 1 deletion examples/ShowSaver.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class ShowSaver {
private:
const std::string m_filename;
std::ofstream m_show_file;
ola::TimeStamp m_last_frame;
ola::TimeStamp m_first_frame;
int64_t m_saved_elapsed_ms;

static const char OLA_SHOW_HEADER[];
};
Expand Down