Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video conversion mishandled multiple events with same timestamp #466

Merged
merged 1 commit into from
Jan 19, 2024
Merged
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
17 changes: 14 additions & 3 deletions pyrdp/player/Replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def registerEvent(pdu: PlayerPDU):
self.duration = (timestamps[-1] - referenceTime) / 1000.0

def __len__(self):
return len(self.events)
return len(self.getSortedEvents())

def __iter__(self):
return ReplayReader(self)
Expand All @@ -79,12 +79,24 @@ def getSortedEvents(self):
"""
return [e for _, events in sorted(self.events.items(), key=lambda pair: pair[0]) for e in events]

def getEventStream(self):
"""
Transform events (dict of list, timestamp: [positions], without repetition)
into an iterable eventStream (list of tuples, [(timestamp, position), ...], with repetition)
"""
return [(timestamp, pos)
for timestamp, positions in sorted(self.events.items(), key=lambda pair: pair[0])
for pos in positions
]


class ReplayReader:
def __init__(self, replay: Replay):
self.replay = replay
self.timestamps = self.replay.getSortedTimestamps()
self.eventPositions = self.replay.getSortedEvents()
self.eventStream = self.replay.getEventStream()

self.player = PlayerLayer()
self.observer = self.player.createObserver(onPDUReceived = lambda: None)
self.n = 0
Expand Down Expand Up @@ -122,8 +134,7 @@ def __next__(self):
if self.n >= len(self.replay):
raise StopIteration

timestamp = self.timestamps[self.n]
position = self.eventPositions[self.n]
timestamp, position = self.eventStream[self.n]
event = self.readEvent(position)

self.n += 1
Expand Down
Loading