-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'nonblocking-callback-api' into passthrough
- Loading branch information
Showing
12 changed files
with
520 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import time | ||
import pprint | ||
|
||
from pupil_audio.nonblocking import PyAudioDeviceMonitor | ||
from pupil_audio.nonblocking import PyAudioBackgroundDeviceMonitor | ||
|
||
|
||
class _LoggingMixin: | ||
def log_prefix(self): | ||
return type(self).__name__ | ||
|
||
def print_devices_by_name(self, devices_by_name): | ||
print("-" * 80) | ||
print(f"{self.log_prefix()}: {list(devices_by_name.keys())}") | ||
|
||
def update(self): | ||
super().update() | ||
self.print_devices_by_name(self.devices_by_name) | ||
|
||
|
||
class _LoggingDeviceMonitor(_LoggingMixin, PyAudioDeviceMonitor): | ||
def log_prefix(self): | ||
return "FOREGROUND" | ||
|
||
|
||
class _LoggingBackgroundDeviceMonitor(_LoggingMixin, PyAudioBackgroundDeviceMonitor): | ||
def log_prefix(self): | ||
return "BACKGROUND" | ||
|
||
|
||
def main(use_foreground=False, use_background=True, delay=0.3): | ||
assert use_foreground or use_background, "At least one flag should be true" | ||
|
||
if use_foreground: | ||
fg_monitor = _LoggingDeviceMonitor() | ||
|
||
if use_background: | ||
bg_monitor = _LoggingBackgroundDeviceMonitor() | ||
bg_monitor.start() | ||
|
||
try: | ||
while True: | ||
if use_foreground: | ||
fg_monitor.update() | ||
time.sleep(delay) | ||
except KeyboardInterrupt: | ||
pass | ||
finally: | ||
if use_foreground: | ||
fg_monitor.cleanup() | ||
if use_background: | ||
bg_monitor.cleanup() | ||
|
||
|
||
if __name__ == "__main__": | ||
import click | ||
|
||
@click.command() | ||
@click.option("--foreground", is_flag=True, help="TODO") | ||
@click.option("--background", is_flag=True, help="TODO") | ||
@click.option("--delay", default=0.3, help="TODO") | ||
def cli(foreground, background, delay): | ||
main( | ||
use_foreground=foreground, | ||
use_background=background, | ||
delay=delay, | ||
) | ||
|
||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .utils.pyaudio import PyAudioManager, HostApiInfo, DeviceInfo, TimeInfo | ||
from .nonblocking.pyaudio import PyAudioDeviceSource, PyAudioDeviceMonitor, PyAudioBackgroundDeviceMonitor | ||
from .nonblocking.pyaudio2pyav import PyAudio2PyAVCapture, PyAudio2PyAVTranscoder | ||
from .nonblocking.pyav import PyAVFileSink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .pyav import PyAVFileSink | ||
from .pyaudio import PyAudioDeviceSource | ||
from .pyaudio import PyAudioDeviceSource, PyAudioDeviceMonitor, PyAudioBackgroundDeviceMonitor | ||
from .pyaudio2pyav import PyAudio2PyAVCapture, PyAudio2PyAVTranscoder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.