Skip to content

Commit

Permalink
Merge branch 'darby_main_original' into test_merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Mar 13, 2024
2 parents 3633144 + 59f5ec6 commit cba0811
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 41 deletions.
5 changes: 4 additions & 1 deletion lib/tlDevice/BMDSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ namespace tl
bool log = true;
while (p.running)
{
const auto t0 = std::chrono::steady_clock::now();

std::vector<DeviceInfo> deviceInfoList;

IDeckLinkIterator* dlIterator = nullptr;
Expand Down Expand Up @@ -201,7 +203,8 @@ namespace tl
}
}

time::sleep(getTickTime());
const auto t1 = std::chrono::steady_clock::now();
time::sleep(getTickTime(), t0, t1);
}

#if defined(_WIN32)
Expand Down
44 changes: 11 additions & 33 deletions lib/tlTimeline/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ namespace tl
p.thread.logTimer = std::chrono::steady_clock::now();
while (p.thread.running)
{
const auto t0 = std::chrono::steady_clock::now();

// Get mutex protected values.
bool clearRequests = false;
bool clearCache = false;
Expand All @@ -221,39 +223,13 @@ namespace tl
// Clear requests.
if (clearRequests)
{
std::vector<std::vector<uint64_t> > ids(1 + p.thread.compare.size());
for (const auto& i : p.thread.videoDataRequests)
{
for (size_t j = 0; j < i.second.size() && j < ids.size(); ++j)
{
ids[j].push_back(i.second[j].id);
}
}
for (const auto& i : p.thread.audioDataRequests)
{
ids[0].push_back(i.second.id);
}
p.timeline->cancelRequests(ids[0]);
for (size_t i = 0; i < p.thread.compare.size(); ++i)
{
p.thread.compare[i]->cancelRequests(ids[i + 1]);
}
p.thread.videoDataRequests.clear();
p.thread.audioDataRequests.clear();
p.clearRequests();
}

// Clear the cache.
if (clearCache)
{
p.thread.videoDataCache.clear();
{
std::unique_lock<std::mutex> lock(p.mutex.mutex);
p.mutex.cacheInfo = PlayerCacheInfo();
}
{
std::unique_lock<std::mutex> lock(p.audioMutex.mutex);
p.audioMutex.audioDataCache.clear();
}
p.clearCache();
}

// Update the cache.
Expand Down Expand Up @@ -321,20 +297,22 @@ namespace tl
}

// Logging.
const auto now = std::chrono::steady_clock::now();
const std::chrono::duration<double> diff = now - p.thread.logTimer;
const auto t1 = std::chrono::steady_clock::now();
const std::chrono::duration<double> diff = t1 - p.thread.logTimer;
if (diff.count() > 10.0)
{
p.thread.logTimer = now;
p.thread.logTimer = t1;
if (auto context = getContext().lock())
{
p.log(context);
}
}

// Sleep for a bit...
time::sleep(p.playerOptions.sleepTimeout);
// Sleep for a bit.
time::sleep(p.playerOptions.sleepTimeout, t0, t1);
}

p.clearRequests();
});
}

Expand Down
40 changes: 38 additions & 2 deletions lib/tlTimeline/PlayerPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,53 @@ namespace tl
return out;
}

void Player::Private::clearRequests()
{
std::vector<std::vector<uint64_t> > ids(1 + thread.compare.size());
for (const auto& i : thread.videoDataRequests)
{
for (size_t j = 0; j < i.second.size() && j < ids.size(); ++j)
{
ids[j].push_back(i.second[j].id);
}
}
for (const auto& i : thread.audioDataRequests)
{
ids[0].push_back(i.second.id);
}
timeline->cancelRequests(ids[0]);
for (size_t i = 0; i < thread.compare.size(); ++i)
{
thread.compare[i]->cancelRequests(ids[i + 1]);
}
thread.videoDataRequests.clear();
thread.audioDataRequests.clear();
}

void Player::Private::clearCache()
{
thread.videoDataCache.clear();
{
std::unique_lock<std::mutex> lock(mutex.mutex);
mutex.cacheInfo = PlayerCacheInfo();
}
{
std::unique_lock<std::mutex> lock(audioMutex.mutex);
audioMutex.audioDataCache.clear();
}
}

void Player::Private::cacheUpdate()
{
// Get the video ranges to be cached.
const otime::TimeRange& timeRange = timeline->getTimeRange();
const otime::RationalTime readAheadDivided(
thread.cacheOptions.readAhead.value() / (1 + thread.compare.size()),
thread.cacheOptions.readAhead.value() / static_cast<double>(1 + thread.compare.size()),
thread.cacheOptions.readAhead.rate());
const otime::RationalTime readAheadRescaled = time::floor(
readAheadDivided.rescaled_to(timeRange.duration().rate()));
const otime::RationalTime readBehindDivided(
thread.cacheOptions.readBehind.value() / (1 + thread.compare.size()),
thread.cacheOptions.readBehind.value() / static_cast<double>(1 + thread.compare.size()),
thread.cacheOptions.readBehind.rate());
const otime::RationalTime readBehindRescaled = time::floor(
readBehindDivided.rescaled_to(timeRange.duration().rate()));
Expand Down
2 changes: 2 additions & 0 deletions lib/tlTimeline/PlayerPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace tl
{
otime::RationalTime loopPlayback(const otime::RationalTime&);

void clearRequests();
void clearCache();
void cacheUpdate();

void resetAudioTime();
Expand Down
17 changes: 12 additions & 5 deletions lib/tlTimeline/TimelinePrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ namespace tl
{
namespace timeline
{
namespace
{
const std::chrono::milliseconds timeout(5);
}

bool Timeline::Private::getVideoInfo(const otio::Composable* composable)
{
if (auto clip = dynamic_cast<const otio::Clip*>(composable))
Expand Down Expand Up @@ -84,14 +89,16 @@ namespace tl

void Timeline::Private::tick()
{
const auto t0 = std::chrono::steady_clock::now();

requests();

// Logging.
const auto now = std::chrono::steady_clock::now();
const std::chrono::duration<float> diff = now - thread.logTimer;
const auto t1 = std::chrono::steady_clock::now();
const std::chrono::duration<float> diff = t1 - thread.logTimer;
if (diff.count() > 10.F)
{
thread.logTimer = now;
thread.logTimer = t1;
if (auto context = this->context.lock())
{
size_t videoRequestsSize = 0;
Expand Down Expand Up @@ -119,8 +126,8 @@ namespace tl
}
}

// Sleep for a bit...
time::sleep(std::chrono::milliseconds(1));
// Sleep for a bit.
time::sleep(timeout, t0, t1);
}

void Timeline::Private::requests()
Expand Down

0 comments on commit cba0811

Please sign in to comment.