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

Fix push operation with a player having chunk_size set to 1 #257

Merged
merged 1 commit into from
May 15, 2024
Merged
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
1 change: 1 addition & 0 deletions doc/changes/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ Version 1.4

- Fix handling of warnings through the logger (:pr:`243` by `Mathieu Scheltienne`_)
- Fix handling of CLI arguments through :class:`~mne_lsl.player.PlayerLSL` entry-point (:pr:`246` by `Mathieu Scheltienne`_)
- Fix push operation by a :class:`~mne_lsl.player.PlayerLSL` with a ``chunk_size`` set to 1 to use :meth:`mne_lsl.lsl.StreamOutlet.push_sample` instead of :meth:`mne_lsl.lsl.StreamOutlet.push_chunk` (:pr:`257` by `Mathieu Scheltienne`_)
5 changes: 4 additions & 1 deletion mne_lsl/player/player_lsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ def _stream(self) -> None:
stop,
self._target_timestamp,
)
self._outlet.push_chunk(data, timestamp=self._target_timestamp)
if self._chunk_size == 1:
self._outlet.push_sample(data[0, :], timestamp=self._target_timestamp)
else:
self._outlet.push_chunk(data, timestamp=self._target_timestamp)
self._stream_annotations(start, stop, start_timestamp)
except Exception as exc:
logger.error("%s: Stopping due to exception: %s", self._name, exc)
Expand Down
17 changes: 17 additions & 0 deletions mne_lsl/player/tests/test_player_lsl.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import time
from datetime import datetime, timezone
from pathlib import Path
Expand Down Expand Up @@ -411,3 +412,19 @@ def test_player_n_repeat_invalid(raw):
Player(raw, n_repeat=-1)
with pytest.raises(TypeError, match="must be an integer"):
Player(raw, n_repeat="1")


@pytest.mark.skipif(
os.getenv("GITHUB_ACTIONS", "") == "true", reason="Unreliable on CIs."
)
def test_player_push_sample(fname):
"""Test pushing individual sample with chunk_size=1."""
name = "Player-test_player_push_sample"
streams = resolve_streams(timeout=0.1)
assert len(streams) == 0
with Player(fname, name=name, chunk_size=1):
streams = resolve_streams()
assert len(streams) == 1
assert streams[0].name == name
streams = resolve_streams(timeout=0.1)
assert len(streams) == 0
Loading