Skip to content

Commit

Permalink
WIP A/B playback sync
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjohnston committed Mar 3, 2024
1 parent ae848be commit 2828c11
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
50 changes: 39 additions & 11 deletions lib/tlTimeline/PlayerPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,12 @@ namespace tl
if (j == thread.videoDataRequests.end())
{
//std::cout << this << " video request: " << time << std::endl;
thread.videoDataRequests[time] = timeline->getVideo(time, ioOptions);
thread.videoDataRequests[time].clear();
thread.videoDataRequests[time].push_back(timeline->getVideo(time, ioOptions));
for (const auto& c : compare)
{
thread.videoDataRequests[time].push_back(c->getVideo(time, ioOptions));
}
}
}
}
Expand All @@ -280,7 +285,12 @@ namespace tl
if (j == thread.videoDataRequests.end())
{
//std::cout << this << " video request: " << time << std::endl;
thread.videoDataRequests[time] = timeline->getVideo(time, ioOptions);
thread.videoDataRequests[time].clear();
thread.videoDataRequests[time].push_back(timeline->getVideo(time, ioOptions));
for (const auto& c : compare)
{
thread.videoDataRequests[time].push_back(c->getVideo(time, ioOptions));
}
}
}
}
Expand Down Expand Up @@ -353,16 +363,32 @@ namespace tl
auto videoDataRequestsIt = thread.videoDataRequests.begin();
while (videoDataRequestsIt != thread.videoDataRequests.end())
{
if (videoDataRequestsIt->second.valid() &&
videoDataRequestsIt->second.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
bool ready = true;
for (auto videoDataRequestIt = videoDataRequestsIt->second.begin();
videoDataRequestIt != videoDataRequestsIt->second.end();
++videoDataRequestIt)
{
auto data = videoDataRequestsIt->second.get();
data.time = videoDataRequestsIt->first;
thread.videoDataCache[data.time] = { data };
ready &= videoDataRequestIt->valid() &&
videoDataRequestIt->wait_for(std::chrono::seconds(0)) == std::future_status::ready;
}
if (ready)
{
const otime::RationalTime time = videoDataRequestsIt->first;
thread.videoDataCache[time].clear();
for (auto videoDataRequestIt = videoDataRequestsIt->second.begin();
videoDataRequestIt != videoDataRequestsIt->second.end();
++videoDataRequestIt)
{
auto data = videoDataRequestIt->get();
data.time = time;
thread.videoDataCache[data.time].push_back(data);
}
videoDataRequestsIt = thread.videoDataRequests.erase(videoDataRequestsIt);
continue;
}
++videoDataRequestsIt;
else
{
++videoDataRequestsIt;
}
}

// Check for finished audio.
Expand All @@ -379,9 +405,11 @@ namespace tl
audioMutex.audioDataCache[audioDataRequestsIt->first] = audioData;
}
audioDataRequestsIt = thread.audioDataRequests.erase(audioDataRequestsIt);
continue;
}
++audioDataRequestsIt;
else
{
++audioDataRequestsIt;
}
}

// Update cached frames.
Expand Down
2 changes: 1 addition & 1 deletion lib/tlTimeline/PlayerPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace tl
struct Thread
{
std::vector<std::shared_ptr<Timeline> > compare;
std::map<otime::RationalTime, std::future<VideoData> > videoDataRequests;
std::map<otime::RationalTime, std::vector<std::future<VideoData> > > videoDataRequests;
std::map<otime::RationalTime, std::vector<VideoData> > videoDataCache;
#if defined(TLRENDER_AUDIO)
std::unique_ptr<RtAudio> rtAudio;
Expand Down

0 comments on commit 2828c11

Please sign in to comment.