aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThéo de la Hogue2024-06-21 03:14:34 +0200
committerThéo de la Hogue2024-06-21 03:14:34 +0200
commit84d9eeb6d8c78991f89720b836254497becd1513 (patch)
tree10f8c43af8e5bc717c5427770fbad305e8ca4fb5
parent503bdfc20e4aaf14b23913ecb93e8ff1c915bc99 (diff)
downloadargaze-84d9eeb6d8c78991f89720b836254497becd1513.zip
argaze-84d9eeb6d8c78991f89720b836254497becd1513.tar.gz
argaze-84d9eeb6d8c78991f89720b836254497becd1513.tar.bz2
argaze-84d9eeb6d8c78991f89720b836254497becd1513.tar.xz
Refactoring waiting in Tobii post processing context.
-rw-r--r--src/argaze/utils/contexts/TobiiProGlasses2.py49
1 files changed, 30 insertions, 19 deletions
diff --git a/src/argaze/utils/contexts/TobiiProGlasses2.py b/src/argaze/utils/contexts/TobiiProGlasses2.py
index 1f7ae13..061813e 100644
--- a/src/argaze/utils/contexts/TobiiProGlasses2.py
+++ b/src/argaze/utils/contexts/TobiiProGlasses2.py
@@ -1154,9 +1154,6 @@ class PostProcessing(ArFeatures.PostProcessingContext):
"s": 1e3
}
- # Initialize inconsistent timestamp monitoring
- self.__last_data_ts = None
-
@property
def segment(self) -> str:
"""Path to segment folder."""
@@ -1257,6 +1254,10 @@ class PostProcessing(ArFeatures.PostProcessingContext):
def __read(self):
"""Iterate on video images and their related data."""
+ last_video_ts = None
+ last_data_ts = None
+
+ # Process video
for video_ts, video_image, data_list in self:
# Check pause event (and stop event)
@@ -1331,15 +1332,6 @@ class PostProcessing(ArFeatures.PostProcessingContext):
data_ts = int(self.__sync_ts + data_ts - self.__sync_data_ts)
- # Catch inconstistent timestamps
- if self.__last_data_ts is not None:
-
- if data_ts - self.__last_data_ts <= 0:
-
- logging.error('! %i gaze position more recent than the previous one', data_ts)
-
- last_data_ts = data_ts
-
# Process gaze positions
match data_object_type:
@@ -1351,19 +1343,41 @@ class PostProcessing(ArFeatures.PostProcessingContext):
if data_object.validity == 0:
# Process timestamped gaze position
- self._process_gaze_position(
- timestamp=data_ts,
- x=int(data_object.value[0] * width),
- y=int(data_object.value[1] * height))
+ self._process_gaze_position(timestamp=data_ts, x=int(data_object.value[0] * width), y=int(data_object.value[1] * height))
else:
# Process empty gaze position
self._process_gaze_position(timestamp=data_ts)
+ # Wait to get a realtime replay
+ # TODO: Add attribute to disable realtime replay
+ # TODO: Consider gaze position processing time to adapt waiting time
+ if last_data_ts is not None:
+
+ # Catch inconstistent gaze position timestamps
+ if data_ts > last_data_ts:
+
+ time.sleep(1e-3) #time.sleep( (data_ts - last_data_ts) * 1e-3 )
+
+ else:
+
+ logging.error('! current gaze position at %i is older than last gaze position at %i', data_ts, last_data_ts)
+
+ last_data_ts = data_ts
+
# Update progression
self.__progression = (video_ts - self.start) / self.__duration
+ # Wait to get a realtime replay
+ # TODO: Add attribute to disable realtime replay
+ # TODO: Consider camera image processing time to adapt waiting time
+ if last_video_ts is not None:
+
+ time.sleep(1e-2) #time.sleep( (video_ts - last_video_ts) * 1e-3 )
+
+ last_video_ts = video_ts
+
# Set stop event ourself
self._stop_event.set()
@@ -1403,9 +1417,6 @@ class PostProcessing(ArFeatures.PostProcessingContext):
data_list.append((next_data_ts, next_data_object, next_data_object_type))
next_data_ts, next_data_object, next_data_object_type = self.__next_data()
- # TODO: Add attribute to disable realtime replay
- time.sleep( (next_video_ts - self.__video_ts) * 1e-3 )
-
# Output video and data
output = self.__video_ts, self.__video_image, data_list