def add_video_device_change_callback(callback): from xpra.platform.webcam import _video_device_change_callbacks, _fire_video_device_change global _watch_manager, _notifier try: import pyinotify except ImportError as e: log.error("Error: cannot watch for video device changes without pyinotify:") log.error(" %s", e) return log("add_video_device_change_callback(%s) pyinotify=%s", callback, pyinotify) if not _watch_manager: class EventHandler(pyinotify.ProcessEvent): def process_IN_CREATE(self, event): _fire_video_device_change(True, event.pathname) def process_IN_DELETE(self, event): _fire_video_device_change(False, event.pathname) _watch_manager = pyinotify.WatchManager() mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE #@UndefinedVariable handler = EventHandler(pevent=_video_device_file_filter) _notifier = pyinotify.ThreadedNotifier(_watch_manager, handler) _notifier.setDaemon(True) wdd = _watch_manager.add_watch('/dev', mask) log("watching for video device changes in /dev") log("notifier=%s, watch=%s", _notifier, wdd) _notifier.start() _video_device_change_callbacks.append(callback)
def add_video_device_change_callback(callback): from xpra.platform.webcam import _video_device_change_callbacks, _fire_video_device_change global _watch_manager, _notifier try: import pyinotify except ImportError as e: log.error( "Error: cannot watch for video device changes without pyinotify:") log.error(" %s", e) return log("add_video_device_change_callback(%s) pyinotify=%s", callback, pyinotify) if not _watch_manager: class EventHandler(pyinotify.ProcessEvent): def process_IN_CREATE(self, event): _fire_video_device_change(True, event.pathname) def process_IN_DELETE(self, event): _fire_video_device_change(False, event.pathname) _watch_manager = pyinotify.WatchManager() mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE #@UndefinedVariable handler = EventHandler(pevent=_video_device_file_filter) _notifier = pyinotify.ThreadedNotifier(_watch_manager, handler) _notifier.setDaemon(True) wdd = _watch_manager.add_watch('/dev', mask) log("watching for video device changes in /dev") log("notifier=%s, watch=%s", _notifier, wdd) _notifier.start() _video_device_change_callbacks.append(callback)
def add_video_device_change_callback(callback): if not get_win32_event_listener: return from xpra.platform.webcam import _video_device_change_callbacks if len(_video_device_change_callbacks)==0: #first callback added, register our handler: get_win32_event_listener().add_event_callback(WM_DEVICECHANGE, callback) _video_device_change_callbacks.append(_device_change_callback)