ok-script 3.0.12__tar.gz → 3.0.13__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ok_script-3.0.12/ok_script.egg-info → ok_script-3.0.13}/PKG-INFO +1 -1
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/capture_methods/browser.py +155 -2
- ok_script-3.0.13/ok/device/capture_methods/browser_webrtc.py +405 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/layout.py +4 -3
- {ok_script-3.0.12 → ok_script-3.0.13/ok_script.egg-info}/PKG-INFO +1 -1
- {ok_script-3.0.12 → ok_script-3.0.13}/ok_script.egg-info/SOURCES.txt +3 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_browser_launch_options.py +11 -1
- ok_script-3.0.13/tests/test_browser_webrtc.py +245 -0
- ok_script-3.0.13/tests/test_browser_webrtc_playwright.py +108 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_kit.py +74 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/.agents/skills/develop/SKILL.md +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/.agents/skills/develop/agents/openai.yaml +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/.agents/skills/develop/references/windows-input.md +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/.agents/skills/generate-templates/SKILL.md +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/.agents/skills/reload-tasks/SKILL.md +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/.agents/skills/reload-tasks/agents/openai.yaml +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/.agents/skills/setup-env/SKILL.md +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/.agents/skills/setup-env/agents/openai.yaml +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/.agents/skills/setup-env/assets/ok-script-develop/SKILL.md +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/.agents/skills/setup-project/SKILL.md +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/.agents/skills/setup-project/agents/openai.yaml +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/.agents/skills/use_venv/SKILL.md +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/.agents/skills/write-test/SKILL.md +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/.agents/skills/write-test/agents/openai.yaml +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/LICENSE.txt +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/MANIFEST.in +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/README.md +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/diagnostics/qq_trace.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/docs/agent-setup.md +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/docs/feature-crops.md +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/docs/mcp.md +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/examples/mcp_observe.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/__main__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/alas/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/alas/emulator_base.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/alas/emulator_windows.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/alas/platform_windows.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/alas/utils.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/assets/default-icon.png +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/capture/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/capture/adb/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/capture/adb/deep.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/capture/adb/minitouch.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/capture/adb/nemu_ipc.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/capture/adb/nemu_utils.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/capture/adb/pool.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/capture/adb/timer.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/capture/adb/util.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/capture/windows/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/capture/windows/d3d11.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/capture/windows/dump.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/cli.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/capture_labels.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/code_runner.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/config_schema.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/downloads.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/events.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/icons.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/mcp_runner.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/mcp_server.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/notifications.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/plugin_staging.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/plugins.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/screenshot.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/script_editing.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/script_packager.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/script_templates.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/skills.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/start_controller.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/task_manager.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/template_store.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/translation.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/core/ui_config.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/DeviceManager.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/browser_audio.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/capture.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/capture_methods/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/capture_methods/adb.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/capture_methods/base.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/capture_methods/bitblt.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/capture_methods/bitblt_utils.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/capture_methods/desktop_duplication.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/capture_methods/hwnd_window.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/capture_methods/image.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/capture_methods/nemu_ipc.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/capture_methods/types.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/capture_methods/update.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/capture_methods/windows_graphics.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/capture_methods/windows_graphics_hdr.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/interaction.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/interaction_methods/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/interaction_methods/adb.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/interaction_methods/base.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/interaction_methods/browser.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/interaction_methods/do_nothing.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/interaction_methods/foreground_post_message.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/interaction_methods/genshin.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/interaction_methods/keys.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/interaction_methods/post_message.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/interaction_methods/pydirect.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/interaction_methods/pynput.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/interaction_methods/swipe.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/device/intercation.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/feature/Box.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/feature/Feature.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/feature/FeatureSet.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/feature/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/gui/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/gui/util/pyappify_startup.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/notification/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/notification/manager.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/notification/messenger_images.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/notification/pipeline.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/notification/ppocr.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/notification/providers.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/notification/system.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/notification/windows_messenger.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ocr/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ocr/download_paddle_model.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/Foundation/Collections.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/Foundation/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/Globalization/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/Graphics/Capture/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/Graphics/DirectX/Direct3D11/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/Graphics/DirectX/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/Graphics/Imaging/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/Graphics/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/Media/Ocr/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/Media/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/Security/Cryptography/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/Security/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/Storage/Streams/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/Storage/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/UI/ViewManagement/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/UI/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/Windows/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/delegate.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/export.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/idldsl.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/inspectable.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/roapi.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/types.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/rotypes/winstring.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/task/DiagnosisTask.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/task/TaskExecutor.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/task/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/task/exceptions.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/task/task.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/test/OKTestRunner.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/test/RunTests.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/test/TaskTestCase.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/test/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/third_party/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/third_party/paperclip.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/overlay/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/overlay/win32_gdi.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/Communicate.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/MainWindow.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/MessageWindow.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/StartController.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/about/AboutTab.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/about/UpdateCard.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/about/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/common/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/common/config.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/debug/OverlayWidget.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/debug/Screenshot.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/debug/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/debug/diagnosis_page.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/events.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/GettextTranslator.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/en_US.qm +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/en_US.ts +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/es_ES.qm +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/es_ES.ts +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/ja_JP.qm +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/ja_JP.ts +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/ko_KR.qm +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/ko_KR.ts +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/path.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/update.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/zh_CN.qm +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/zh_CN.ts +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/zh_TW.qm +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/i18n/zh_TW.ts +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/buttons.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/cards.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/dialogs.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/feedback.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/gallery.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/icons.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/inputs.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/labels.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/mica.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/motion.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/navigation.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/options.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/popover.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/qss.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/switch.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/table.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/tabs.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/theme.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/kit/window.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/overlay/OverlayWindow.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/overlay/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/plugins/PluginTab.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/plugins/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/plugins/imported_tabs.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/qt.qrc +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/resources.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/settings/GlobalConfigTab.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/settings/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/settings/config_section.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/settings/settings_page.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/shell/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/shell/connection.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/shell/diagnostics.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/shell/lazy_page.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/shell/log_page.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/shell/nav_icons.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/shell/run_bar.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/start/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/EditTaskTab.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/MarkUpWindow.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/ModifyListDialog.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/PythonHighlighter.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/RecordScript.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/ScheduleTaskTab.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/ScriptPackager.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/TaskManger.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/TaskOpButton.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/TemplateFactory.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/TemplateTab.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/config_editors.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/config_form.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/mouse_buttons.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/schedule_index_sync.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/tasks/tasks_page.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/util/Alert.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/util/InitWorker.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/util/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/util/app.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/util/download.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/util/pip_util.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/util/pyappify_startup.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/util/touch_scroll.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/util/windows_thumbnail.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/widget/Card.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/widget/CustomTab.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/widget/FlowLayout.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/widget/ImageWidget.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/widget/ImportWarningDialog.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/widget/ListTableWidgetItem.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/widget/NumericTableWidgetItem.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/widget/SortingTableWidgetItem.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/widget/StartLoadingDialog.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/widget/Tab.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/widget/TabWidget.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/widget/UpdateConfigWidgetItem.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/widget/YesNonWidgetItem.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/ui/qt/widget/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/update/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/update/copy_ok_folder.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/update/inline_ok_requirements.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/Analytics.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/GlobalConfig.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/__init__.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/blur.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/clazz.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/collection.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/color.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/config.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/explorer.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/file.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/gpu_driver_settings.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/handler.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/i18n.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/logger.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/partial_sync_repo.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/print_hwnd.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/process.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/shortcut.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/version.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/window.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok/util/windows_schedule.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok_script.egg-info/dependency_links.txt +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok_script.egg-info/entry_points.txt +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok_script.egg-info/not-zip-safe +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok_script.egg-info/requires.txt +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/ok_script.egg-info/top_level.txt +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/pyproject.toml +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/setup.cfg +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/setup.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_app.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_base_interaction.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_blur.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_box.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_browser_audio.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_browser_audio_playwright.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_browser_geometry.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_browser_pointer_lock_playwright.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_capture_update.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_cli.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_core_events.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_core_ui_services.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_device_manager.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_diagnosis_page.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_executor_jobs.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_explorer.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_global_config.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_gpu_driver_settings.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_handler.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_headless_imports.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_inline_ok_requirements.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_lazy_page.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_log_page.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_logger.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_main_window_notifications.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_main_window_startup_tab.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_main_window_system_theme.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_markup_window.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_mcp_cleanup.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_mcp_runner.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_mcp_server.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_mcp_setting.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_missing_frame.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_mouse_buttons.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_navigation_state.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_nemu_ipc_capture.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_notifications.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_ok_mutex.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_overlay_custom_draw.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_overlay_lifecycle.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_package_metadata.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_plugin_staging.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_plugin_tabs.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_plugins.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_post_message_activation.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_process.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_process_mutex.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_pyappify_startup_update.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_qt_events.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_qt_page_layout.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_runtime_startup.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_schedule_startup.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_schedule_task_index_sync.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_screenshot_naming.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_screenshot_rendering.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_settings_page.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_shell.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_shortcut.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_skills.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_start_controller.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_task_executor_error_screenshot.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_task_executor_next_frame.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_task_executor_queue.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_task_reloading.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_tasks_page.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_template_compression.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_template_generation.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_template_tab.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_touch_scroll.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_translation_fallback.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_ui_config.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_version.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_windows_graphics_capture.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_windows_graphics_hdr.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_windows_schedule_target_parse.py +0 -0
- {ok_script-3.0.12 → ok_script-3.0.13}/tests/test_windows_schedule_xml.py +0 -0
|
@@ -3,21 +3,40 @@ import ctypes
|
|
|
3
3
|
import os
|
|
4
4
|
import re
|
|
5
5
|
import threading
|
|
6
|
+
import time
|
|
7
|
+
from urllib.parse import urlsplit
|
|
6
8
|
from ctypes import wintypes
|
|
7
9
|
|
|
10
|
+
import cv2
|
|
11
|
+
import numpy as np
|
|
8
12
|
import win32con
|
|
9
13
|
import win32gui
|
|
10
14
|
|
|
11
15
|
from ok.core.events import communicate
|
|
12
|
-
from ok.task.exceptions import CaptureException
|
|
16
|
+
from ok.task.exceptions import CaptureBusyException, CaptureException
|
|
13
17
|
from ok.util.logger import Logger
|
|
14
18
|
from ok.util.window import DWMWA_EXTENDED_FRAME_BOUNDS, windows_graphics_available, find_hwnd
|
|
15
19
|
|
|
16
20
|
from ok.device.capture_methods.base import BaseCaptureMethod
|
|
21
|
+
from ok.device.capture_methods.browser_webrtc import (
|
|
22
|
+
PEER_CONNECTION_REGISTRY_JS,
|
|
23
|
+
STATUS_ENDED,
|
|
24
|
+
TAP_JS,
|
|
25
|
+
WebRtcFrameReceiver,
|
|
26
|
+
parse_message,
|
|
27
|
+
place_in_viewport,
|
|
28
|
+
)
|
|
17
29
|
from ok.device.capture_methods.windows_graphics import WindowsGraphicsCaptureMethod
|
|
18
30
|
|
|
19
31
|
logger = Logger.get_logger(__name__)
|
|
20
32
|
|
|
33
|
+
# WebRTC capture mode: how often to look for (or re-check) the page's video, and how long a
|
|
34
|
+
# Playwright screenshot may take when there is no video.
|
|
35
|
+
TAP_CHECK_INTERVAL = 1.0
|
|
36
|
+
SCREENSHOT_TIMEOUT_MS = 3000
|
|
37
|
+
FRAME_SOURCE_TIMEOUT = 10
|
|
38
|
+
TAP_RETRY_AFTER_FAILURE = 30
|
|
39
|
+
|
|
21
40
|
# Pages ask for pointer lock on mouse down (e.g. cloud game SDKs). The automated browser window is
|
|
22
41
|
# usually not the OS foreground window, so Chromium rejects the lock (pointerlockerror) and such pages
|
|
23
42
|
# fall back to cursor mode, drop the click or send Esc. Fake a granted lock; pages still release it
|
|
@@ -53,8 +72,25 @@ FAKE_POINTER_LOCK_JS = '''() => {
|
|
|
53
72
|
|
|
54
73
|
|
|
55
74
|
class BrowserCaptureMethod(BaseCaptureMethod):
|
|
75
|
+
"""Run the target page in a Playwright-controlled system browser and capture it.
|
|
76
|
+
|
|
77
|
+
Browser config keys (app config 'browser'):
|
|
78
|
+
url: page to open.
|
|
79
|
+
resolution: page viewport (width, height); default (1280, 720).
|
|
80
|
+
channels: browsers to try in order; default ['msedge', 'chrome', 'chromium'].
|
|
81
|
+
args: extra browser command-line arguments.
|
|
82
|
+
navigation_timeout: seconds to wait for the page to load; default 60, 0 waits without limit.
|
|
83
|
+
fake_pointer_lock: grant pointer lock requests without OS focus; default True.
|
|
84
|
+
capture: 'wgc' (default) captures the browser window with Windows Graphics Capture.
|
|
85
|
+
'webrtc' reads the decoded frames of the page's largest WebRTC <video> directly (or,
|
|
86
|
+
when the page draws the stream on a canvas, the video track its peer connection
|
|
87
|
+
receives), which keeps working while the window is minimized but captures only the
|
|
88
|
+
video (page elements over or around it are black) and uses more CPU. While the page
|
|
89
|
+
shows no such video, frames come from Playwright screenshots, which are slower.
|
|
90
|
+
"""
|
|
56
91
|
name = "Browser Capture"
|
|
57
92
|
description = "Capture from Browser using Playwright and Windows Graphics Capture"
|
|
93
|
+
capture_mode = 'wgc'
|
|
58
94
|
|
|
59
95
|
def __init__(self, config, exit_event, global_config=None):
|
|
60
96
|
super().__init__()
|
|
@@ -70,6 +106,13 @@ class BrowserCaptureMethod(BaseCaptureMethod):
|
|
|
70
106
|
self.page = None
|
|
71
107
|
self.latest_frame = None
|
|
72
108
|
self.wgc_capture = None
|
|
109
|
+
self.capture_mode = config.get('capture', 'wgc')
|
|
110
|
+
self._webrtc = None
|
|
111
|
+
self._tap_offset = (0.0, 0.0)
|
|
112
|
+
self._next_tap_check = 0.0
|
|
113
|
+
self._frame_source = None
|
|
114
|
+
self._frame_lock = threading.Lock()
|
|
115
|
+
self._loopback_origins = set()
|
|
73
116
|
self.loop = asyncio.new_event_loop()
|
|
74
117
|
self.loop_thread = threading.Thread(target=self._start_loop, daemon=True, name="PlaywrightLoop")
|
|
75
118
|
self.loop_thread.start()
|
|
@@ -114,6 +157,7 @@ class BrowserCaptureMethod(BaseCaptureMethod):
|
|
|
114
157
|
async def _launch_browser_async(self):
|
|
115
158
|
from playwright.async_api import async_playwright
|
|
116
159
|
self.playwright = await async_playwright().start()
|
|
160
|
+
self._loopback_origins = set()
|
|
117
161
|
|
|
118
162
|
width, height = self._size
|
|
119
163
|
|
|
@@ -159,6 +203,8 @@ class BrowserCaptureMethod(BaseCaptureMethod):
|
|
|
159
203
|
fake_pointer_lock = self.config.get('fake_pointer_lock', True)
|
|
160
204
|
if fake_pointer_lock:
|
|
161
205
|
await self.browser.add_init_script(script=f'({FAKE_POINTER_LOCK_JS})()')
|
|
206
|
+
if self.capture_mode == 'webrtc':
|
|
207
|
+
await self.browser.add_init_script(script=f'({PEER_CONNECTION_REGISTRY_JS})()')
|
|
162
208
|
|
|
163
209
|
await asyncio.sleep(0.1)
|
|
164
210
|
|
|
@@ -195,6 +241,9 @@ class BrowserCaptureMethod(BaseCaptureMethod):
|
|
|
195
241
|
if fake_pointer_lock:
|
|
196
242
|
# A reused page loaded before the init script was registered.
|
|
197
243
|
await self.page.evaluate(FAKE_POINTER_LOCK_JS)
|
|
244
|
+
if self.capture_mode == 'webrtc':
|
|
245
|
+
# Connections a reused page already created stay unregistered until it reloads.
|
|
246
|
+
await self.page.evaluate(PEER_CONNECTION_REGISTRY_JS)
|
|
198
247
|
|
|
199
248
|
await self.page.bring_to_front()
|
|
200
249
|
await self.page.set_viewport_size({'width': width, 'height': height})
|
|
@@ -226,7 +275,8 @@ class BrowserCaptureMethod(BaseCaptureMethod):
|
|
|
226
275
|
|
|
227
276
|
logger.info(
|
|
228
277
|
f"Browser window '{target_title}' found: {self.hwnd} offsets: {self.x_offset},{self.y_offset} size: {self._size}")
|
|
229
|
-
self.
|
|
278
|
+
if self.capture_mode != 'webrtc':
|
|
279
|
+
self.wgc_capture = BrowserWGC(self)
|
|
230
280
|
if getattr(self, 'global_config', None) is not None:
|
|
231
281
|
from ok.device.browser_audio import BrowserAudioMute
|
|
232
282
|
self._audio_mute = BrowserAudioMute(
|
|
@@ -309,6 +359,9 @@ class BrowserCaptureMethod(BaseCaptureMethod):
|
|
|
309
359
|
|
|
310
360
|
def close(self):
|
|
311
361
|
logger.info(f'BrowserCaptureMethod close browser')
|
|
362
|
+
if self._webrtc is not None:
|
|
363
|
+
self._webrtc.close()
|
|
364
|
+
self._webrtc = None
|
|
312
365
|
if self.wgc_capture:
|
|
313
366
|
self.wgc_capture.close()
|
|
314
367
|
self.wgc_capture = None
|
|
@@ -353,6 +406,15 @@ class BrowserCaptureMethod(BaseCaptureMethod):
|
|
|
353
406
|
communicate.notification.emit('Paused because browser exited', None, True, True, "start", None, None)
|
|
354
407
|
return None
|
|
355
408
|
|
|
409
|
+
if self.capture_mode == 'webrtc':
|
|
410
|
+
acquired = self._frame_lock.acquire(timeout=timeout) if timeout > 0 else self._frame_lock.acquire(False)
|
|
411
|
+
if not acquired:
|
|
412
|
+
raise CaptureBusyException('Browser capture is busy')
|
|
413
|
+
try:
|
|
414
|
+
return self._webrtc_or_screenshot_frame()
|
|
415
|
+
finally:
|
|
416
|
+
self._frame_lock.release()
|
|
417
|
+
|
|
356
418
|
if self.wgc_capture:
|
|
357
419
|
if not self.update_window_geometry():
|
|
358
420
|
return None
|
|
@@ -360,6 +422,97 @@ class BrowserCaptureMethod(BaseCaptureMethod):
|
|
|
360
422
|
|
|
361
423
|
return None
|
|
362
424
|
|
|
425
|
+
def _webrtc_or_screenshot_frame(self):
|
|
426
|
+
frame, source = self._webrtc_frame(), 'WebRTC video'
|
|
427
|
+
if frame is None:
|
|
428
|
+
frame, source = self._screenshot_frame(), 'Playwright screenshot'
|
|
429
|
+
if frame is not None and source != self._frame_source:
|
|
430
|
+
logger.info(f'BrowserCaptureMethod capturing from {source}')
|
|
431
|
+
self._frame_source = source
|
|
432
|
+
return frame
|
|
433
|
+
|
|
434
|
+
def _webrtc_frame(self):
|
|
435
|
+
if self._webrtc is None:
|
|
436
|
+
self._webrtc = WebRtcFrameReceiver()
|
|
437
|
+
if time.monotonic() >= self._next_tap_check:
|
|
438
|
+
# Also re-checks a running tap: the page may have replaced or moved its video.
|
|
439
|
+
self._next_tap_check = time.monotonic() + TAP_CHECK_INTERVAL
|
|
440
|
+
result, offset = self._run_quietly(self._install_tap_async()) or ('error', None)
|
|
441
|
+
if result != 'ok':
|
|
442
|
+
if result == 'ws-failed':
|
|
443
|
+
logger.warning('BrowserCaptureMethod page cannot connect to the WebRTC frame receiver; '
|
|
444
|
+
f'retrying in {TAP_RETRY_AFTER_FAILURE}s')
|
|
445
|
+
self._next_tap_check = time.monotonic() + TAP_RETRY_AFTER_FAILURE
|
|
446
|
+
self._webrtc.disconnect()
|
|
447
|
+
return None
|
|
448
|
+
self._tap_offset = offset
|
|
449
|
+
message = self._webrtc.request()
|
|
450
|
+
if message is None:
|
|
451
|
+
return None
|
|
452
|
+
status, frame, content_rect, element_rect = parse_message(message)
|
|
453
|
+
if status == STATUS_ENDED:
|
|
454
|
+
self._webrtc.disconnect()
|
|
455
|
+
self._next_tap_check = 0.0
|
|
456
|
+
if frame is None:
|
|
457
|
+
return None
|
|
458
|
+
return place_in_viewport(frame, content_rect, element_rect, self._size, self._tap_offset)
|
|
459
|
+
|
|
460
|
+
async def _install_tap_async(self):
|
|
461
|
+
"""Stream from the largest live WebRTC video in any frame of the page.
|
|
462
|
+
|
|
463
|
+
Returns ('ok', offset of that frame in the page), ('no-video', None) or ('ws-failed', None).
|
|
464
|
+
"""
|
|
465
|
+
page = self.page
|
|
466
|
+
frames = [page.main_frame] + [f for f in page.frames if f != page.main_frame]
|
|
467
|
+
result = 'no-video'
|
|
468
|
+
for frame in frames:
|
|
469
|
+
try:
|
|
470
|
+
await self._allow_loopback_async(frame.url)
|
|
471
|
+
status = await frame.evaluate(TAP_JS, {'wsUrl': self._webrtc.url})
|
|
472
|
+
if status == 'ws-failed':
|
|
473
|
+
result = status
|
|
474
|
+
if status != 'ok':
|
|
475
|
+
continue
|
|
476
|
+
if frame == page.main_frame:
|
|
477
|
+
return 'ok', (0.0, 0.0)
|
|
478
|
+
box = await (await frame.frame_element()).bounding_box()
|
|
479
|
+
if box is not None:
|
|
480
|
+
return 'ok', (box['x'], box['y'])
|
|
481
|
+
except Exception as e:
|
|
482
|
+
logger.debug(f'WebRTC tap not installed in {frame.url}: {e}')
|
|
483
|
+
return result, None
|
|
484
|
+
|
|
485
|
+
async def _allow_loopback_async(self, url):
|
|
486
|
+
"""Let a public page reach the loopback frame receiver without Chrome's Local Network Access prompt."""
|
|
487
|
+
parts = urlsplit(url)
|
|
488
|
+
if parts.scheme not in ('http', 'https'):
|
|
489
|
+
return
|
|
490
|
+
origin = f'{parts.scheme}://{parts.netloc}'
|
|
491
|
+
if origin in self._loopback_origins:
|
|
492
|
+
return
|
|
493
|
+
self._loopback_origins.add(origin)
|
|
494
|
+
try:
|
|
495
|
+
await self.browser.grant_permissions(['local-network-access'], origin=origin)
|
|
496
|
+
except Exception as e:
|
|
497
|
+
logger.info(f'BrowserCaptureMethod cannot grant local network access to {origin}: {e}')
|
|
498
|
+
|
|
499
|
+
def _screenshot_frame(self):
|
|
500
|
+
data = self._run_quietly(self.page.screenshot(type='png', timeout=SCREENSHOT_TIMEOUT_MS))
|
|
501
|
+
if not data:
|
|
502
|
+
return None
|
|
503
|
+
return cv2.imdecode(np.frombuffer(data, np.uint8), cv2.IMREAD_COLOR)
|
|
504
|
+
|
|
505
|
+
def _run_quietly(self, coro):
|
|
506
|
+
"""run_in_loop without error logs: frame polling failures are expected (navigation, minimized)."""
|
|
507
|
+
if not self.loop.is_running():
|
|
508
|
+
coro.close()
|
|
509
|
+
return None
|
|
510
|
+
try:
|
|
511
|
+
return asyncio.run_coroutine_threadsafe(coro, self.loop).result(FRAME_SOURCE_TIMEOUT)
|
|
512
|
+
except Exception as e:
|
|
513
|
+
logger.debug(f'BrowserCaptureMethod frame source failed: {e}')
|
|
514
|
+
return None
|
|
515
|
+
|
|
363
516
|
def connected(self):
|
|
364
517
|
connected = self.page is not None and not self.page.is_closed()
|
|
365
518
|
return connected
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
"""Capture the decoded frames of a page's WebRTC video track.
|
|
2
|
+
|
|
3
|
+
A script injected into the page keeps the newest decoded VideoFrame of the largest live WebRTC
|
|
4
|
+
video and copies it to Python over a loopback WebSocket when asked. Python places the frame where
|
|
5
|
+
the video is drawn in the page, so frames use the same coordinates as Playwright input.
|
|
6
|
+
|
|
7
|
+
Some pages (e.g. the cloud game SDK in its canvas player mode) draw the stream on a <canvas> and
|
|
8
|
+
leave no <video> playing it. For those the tap reads the video track a peer connection receives,
|
|
9
|
+
which PEER_CONNECTION_REGISTRY_JS records when the page creates the connection.
|
|
10
|
+
|
|
11
|
+
Unlike Windows Graphics Capture this keeps working while the browser window is minimized, but it
|
|
12
|
+
only sees the video: page elements drawn over or around it are not captured.
|
|
13
|
+
"""
|
|
14
|
+
import base64
|
|
15
|
+
import hashlib
|
|
16
|
+
import os
|
|
17
|
+
import socket
|
|
18
|
+
import struct
|
|
19
|
+
import threading
|
|
20
|
+
|
|
21
|
+
import cv2
|
|
22
|
+
import numpy as np
|
|
23
|
+
|
|
24
|
+
from ok.util.logger import Logger
|
|
25
|
+
|
|
26
|
+
logger = Logger.get_logger(__name__)
|
|
27
|
+
|
|
28
|
+
WS_GUID = b'258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
|
|
29
|
+
MAGIC = 0x4f4b5450
|
|
30
|
+
|
|
31
|
+
STATUS_FRAME = 1
|
|
32
|
+
STATUS_NO_FRAME = 2
|
|
33
|
+
STATUS_ENDED = 3
|
|
34
|
+
|
|
35
|
+
FORMAT_BGRA = 1
|
|
36
|
+
FORMAT_I420 = 2
|
|
37
|
+
FORMAT_NV12 = 3
|
|
38
|
+
|
|
39
|
+
# Header (u32 unless noted): magic, status, width, height, format, (offset, stride) x3,
|
|
40
|
+
# then f32 x, y, width, height of the drawn video content in CSS pixels of the page viewport,
|
|
41
|
+
# then f32 x, y, width, height of the visible video element (clips object-fit: cover).
|
|
42
|
+
HEADER_SIZE = 80
|
|
43
|
+
|
|
44
|
+
# Init script: remember every RTCPeerConnection the page creates, so the tap can find the received
|
|
45
|
+
# video track when the page draws it without a <video>. Must run before the page creates its
|
|
46
|
+
# connection; connections created earlier are not found.
|
|
47
|
+
PEER_CONNECTION_REGISTRY_JS = '''() => {
|
|
48
|
+
const Native = window.RTCPeerConnection;
|
|
49
|
+
if (!Native || window.__okPeerConnections) return true;
|
|
50
|
+
const connections = window.__okPeerConnections = [];
|
|
51
|
+
const Registered = new Proxy(Native, {
|
|
52
|
+
construct(target, args, newTarget) {
|
|
53
|
+
const pc = Reflect.construct(target, args, newTarget);
|
|
54
|
+
connections.push(new WeakRef(pc));
|
|
55
|
+
return pc;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
if (window.webkitRTCPeerConnection === Native) window.webkitRTCPeerConnection = Registered;
|
|
59
|
+
window.RTCPeerConnection = Registered;
|
|
60
|
+
return true;
|
|
61
|
+
}'''
|
|
62
|
+
|
|
63
|
+
# Returns 'ok' when a tap is streaming from the current video, 'no-video', or 'ws-failed' when the
|
|
64
|
+
# page cannot connect to the receiver.
|
|
65
|
+
# Runs in each frame of the page; the rectangles are relative to that frame's viewport.
|
|
66
|
+
# Prefers the largest <video> playing a live WebRTC stream. Without one, it reads the largest live
|
|
67
|
+
# video track received by a registered peer connection and assumes it fills the page's largest
|
|
68
|
+
# canvas or video element (the whole viewport if there is none).
|
|
69
|
+
TAP_JS = r'''async ({wsUrl}) => {
|
|
70
|
+
const liveTrack = (s) => s instanceof MediaStream ?
|
|
71
|
+
s.getVideoTracks().find(t => t.readyState === 'live') : undefined;
|
|
72
|
+
const area = (el) => { const r = el.getBoundingClientRect(); return r.width * r.height; };
|
|
73
|
+
const pick = () => {
|
|
74
|
+
let best = null, bestArea = 0;
|
|
75
|
+
for (const v of document.querySelectorAll('video')) {
|
|
76
|
+
const source = liveTrack(v.srcObject);
|
|
77
|
+
if (!source || !v.videoWidth || area(v) <= bestArea) continue;
|
|
78
|
+
bestArea = area(v);
|
|
79
|
+
best = {source, video: v, element: v};
|
|
80
|
+
}
|
|
81
|
+
if (best) return best;
|
|
82
|
+
const connections = window.__okPeerConnections || [];
|
|
83
|
+
let source = null, pixels = -1;
|
|
84
|
+
for (let i = connections.length - 1; i >= 0; i--) {
|
|
85
|
+
const pc = connections[i].deref();
|
|
86
|
+
if (!pc || pc.signalingState === 'closed') { connections.splice(i, 1); continue; }
|
|
87
|
+
for (const r of pc.getReceivers()) {
|
|
88
|
+
const t = r.track;
|
|
89
|
+
if (!t || t.kind !== 'video' || t.readyState !== 'live' || t.muted) continue;
|
|
90
|
+
const s = t.getSettings();
|
|
91
|
+
if ((s.width || 0) * (s.height || 0) > pixels) { pixels = (s.width || 0) * (s.height || 0); source = t; }
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (!source) return null;
|
|
95
|
+
let element = null;
|
|
96
|
+
bestArea = 0;
|
|
97
|
+
for (const el of document.querySelectorAll('canvas, video')) {
|
|
98
|
+
if (area(el) > bestArea) { bestArea = area(el); element = el; }
|
|
99
|
+
}
|
|
100
|
+
return {source, video: null, element};
|
|
101
|
+
};
|
|
102
|
+
const old = window.__okWebRtcTap;
|
|
103
|
+
const current = pick();
|
|
104
|
+
if (old) {
|
|
105
|
+
if (old.wsUrl === wsUrl && old.ws.readyState === WebSocket.OPEN && !old.ended && current &&
|
|
106
|
+
current.source === old.source && current.element === old.element) {
|
|
107
|
+
return 'ok';
|
|
108
|
+
}
|
|
109
|
+
old.close();
|
|
110
|
+
}
|
|
111
|
+
if (!current) return 'no-video';
|
|
112
|
+
const {source, video, element} = current;
|
|
113
|
+
const track = source.clone();
|
|
114
|
+
const reader = new MediaStreamTrackProcessor({track}).readable.getReader();
|
|
115
|
+
const tap = {wsUrl, source, video, element, latest: null, ended: false};
|
|
116
|
+
tap.close = () => {
|
|
117
|
+
tap.ended = true;
|
|
118
|
+
try { reader.cancel(); } catch (e) {}
|
|
119
|
+
track.stop();
|
|
120
|
+
if (tap.latest) { tap.latest.close(); tap.latest = null; }
|
|
121
|
+
try { tap.ws.close(); } catch (e) {}
|
|
122
|
+
};
|
|
123
|
+
(async () => {
|
|
124
|
+
try {
|
|
125
|
+
for (;;) {
|
|
126
|
+
const {value, done} = await reader.read();
|
|
127
|
+
if (done) break;
|
|
128
|
+
if (tap.latest) tap.latest.close();
|
|
129
|
+
tap.latest = value;
|
|
130
|
+
}
|
|
131
|
+
} catch (e) {}
|
|
132
|
+
tap.ended = true;
|
|
133
|
+
})();
|
|
134
|
+
const contentRect = () => {
|
|
135
|
+
const r = element ? element.getBoundingClientRect() :
|
|
136
|
+
{left: 0, top: 0, width: window.innerWidth, height: window.innerHeight};
|
|
137
|
+
const vw = video ? video.videoWidth : 0, vh = video ? video.videoHeight : 0;
|
|
138
|
+
let fit = video ? getComputedStyle(video).objectFit : 'fill';
|
|
139
|
+
let w = r.width, h = r.height;
|
|
140
|
+
if (fit === 'scale-down') fit = (vw <= r.width && vh <= r.height) ? 'none' : 'contain';
|
|
141
|
+
if (vw && vh && fit !== 'fill') {
|
|
142
|
+
const s = fit === 'none' ? 1 : (fit === 'cover' ? Math.max : Math.min)(r.width / vw, r.height / vh);
|
|
143
|
+
w = vw * s; h = vh * s;
|
|
144
|
+
}
|
|
145
|
+
return [r.left + (r.width - w) / 2, r.top + (r.height - h) / 2, w, h, r.left, r.top, r.width, r.height];
|
|
146
|
+
};
|
|
147
|
+
const FORMATS = {BGRA: 1, BGRX: 1, I420: 2, NV12: 3};
|
|
148
|
+
const reply = (status) => {
|
|
149
|
+
const buf = new ArrayBuffer(80);
|
|
150
|
+
new Uint32Array(buf, 0, 2).set([0x4f4b5450, status]);
|
|
151
|
+
tap.ws.send(buf);
|
|
152
|
+
};
|
|
153
|
+
tap.ws = new WebSocket(wsUrl);
|
|
154
|
+
tap.ws.binaryType = 'arraybuffer';
|
|
155
|
+
tap.ws.onmessage = async () => {
|
|
156
|
+
if (tap.ended) return reply(3);
|
|
157
|
+
if (!tap.latest) return reply(2);
|
|
158
|
+
const f = tap.latest.clone();
|
|
159
|
+
try {
|
|
160
|
+
const nativeFormat = f.format === 'I420' || f.format === 'NV12';
|
|
161
|
+
const opts = nativeFormat ? {} : {format: 'BGRA'};
|
|
162
|
+
const buf = new ArrayBuffer(80 + f.allocationSize(opts));
|
|
163
|
+
const layout = await f.copyTo(new Uint8Array(buf, 80), opts);
|
|
164
|
+
const header = new Uint32Array(buf, 0, 11);
|
|
165
|
+
header.set([0x4f4b5450, 1, f.visibleRect.width, f.visibleRect.height,
|
|
166
|
+
FORMATS[nativeFormat ? f.format : 'BGRA']]);
|
|
167
|
+
layout.forEach((p, i) => { header[5 + i * 2] = p.offset; header[6 + i * 2] = p.stride; });
|
|
168
|
+
new Float32Array(buf, 48, 8).set(contentRect());
|
|
169
|
+
tap.ws.send(buf);
|
|
170
|
+
} catch (e) {
|
|
171
|
+
reply(2);
|
|
172
|
+
} finally {
|
|
173
|
+
f.close();
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
tap.ws.onclose = () => { tap.ended = true; };
|
|
177
|
+
// A blocked loopback connection (e.g. Local Network Access not granted) may never open or fail.
|
|
178
|
+
const opened = await new Promise(resolve => {
|
|
179
|
+
tap.ws.onopen = () => resolve(true);
|
|
180
|
+
tap.ws.onerror = () => resolve(false);
|
|
181
|
+
setTimeout(() => resolve(false), 3000);
|
|
182
|
+
});
|
|
183
|
+
if (!opened) { tap.close(); return 'ws-failed'; }
|
|
184
|
+
window.__okWebRtcTap = tap;
|
|
185
|
+
return 'ok';
|
|
186
|
+
}'''
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class WebRtcFrameReceiver:
|
|
190
|
+
"""Loopback WebSocket server for one page tap at a time.
|
|
191
|
+
|
|
192
|
+
The browser's WebSocket stack is the throughput limit (about 12 ms per 720p frame), so this
|
|
193
|
+
reads each message straight into one reused buffer instead of using a general WebSocket library.
|
|
194
|
+
"""
|
|
195
|
+
|
|
196
|
+
def __init__(self):
|
|
197
|
+
self.token = base64.urlsafe_b64encode(os.urandom(16)).decode().rstrip('=')
|
|
198
|
+
self.listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
199
|
+
self.listener.bind(('127.0.0.1', 0))
|
|
200
|
+
self.listener.listen(4)
|
|
201
|
+
self.url = f'ws://127.0.0.1:{self.listener.getsockname()[1]}/{self.token}'
|
|
202
|
+
self.lock = threading.Lock()
|
|
203
|
+
self.sock = None
|
|
204
|
+
self.buf = bytearray(8 << 20)
|
|
205
|
+
self.closed = False
|
|
206
|
+
threading.Thread(target=self._accept_loop, daemon=True, name='WebRtcFrameReceiver').start()
|
|
207
|
+
|
|
208
|
+
@property
|
|
209
|
+
def connected(self):
|
|
210
|
+
return self.sock is not None
|
|
211
|
+
|
|
212
|
+
def _accept_loop(self):
|
|
213
|
+
while not self.closed:
|
|
214
|
+
try:
|
|
215
|
+
sock, _ = self.listener.accept()
|
|
216
|
+
except OSError:
|
|
217
|
+
return
|
|
218
|
+
try:
|
|
219
|
+
self._handshake(sock)
|
|
220
|
+
except Exception as e:
|
|
221
|
+
logger.debug(f'WebRTC tap handshake rejected: {e}')
|
|
222
|
+
sock.close()
|
|
223
|
+
continue
|
|
224
|
+
with self.lock:
|
|
225
|
+
old, self.sock = self.sock, sock
|
|
226
|
+
if old is not None:
|
|
227
|
+
old.close()
|
|
228
|
+
|
|
229
|
+
def _handshake(self, sock):
|
|
230
|
+
sock.settimeout(5)
|
|
231
|
+
request = b''
|
|
232
|
+
while b'\r\n\r\n' not in request:
|
|
233
|
+
chunk = sock.recv(4096)
|
|
234
|
+
if not chunk or len(request) > 65536:
|
|
235
|
+
raise ConnectionError('incomplete handshake')
|
|
236
|
+
request += chunk
|
|
237
|
+
lines = request.split(b'\r\n')
|
|
238
|
+
if lines[0].split(b' ')[1].lstrip(b'/') != self.token.encode():
|
|
239
|
+
raise ConnectionError('wrong token')
|
|
240
|
+
key = next(line.split(b':', 1)[1].strip() for line in lines
|
|
241
|
+
if line.lower().startswith(b'sec-websocket-key:'))
|
|
242
|
+
accept = base64.b64encode(hashlib.sha1(key + WS_GUID).digest())
|
|
243
|
+
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
|
244
|
+
sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 8 << 20)
|
|
245
|
+
sock.sendall(b'HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n'
|
|
246
|
+
b'Sec-WebSocket-Accept: ' + accept + b'\r\n\r\n')
|
|
247
|
+
|
|
248
|
+
def _read_exact(self, sock, view):
|
|
249
|
+
got = 0
|
|
250
|
+
while got < len(view):
|
|
251
|
+
n = sock.recv_into(view[got:])
|
|
252
|
+
if n == 0:
|
|
253
|
+
raise ConnectionError('WebRTC tap disconnected')
|
|
254
|
+
got += n
|
|
255
|
+
|
|
256
|
+
def _read_message(self, sock):
|
|
257
|
+
total = 0
|
|
258
|
+
small = bytearray(8)
|
|
259
|
+
while True:
|
|
260
|
+
self._read_exact(sock, memoryview(small)[:2])
|
|
261
|
+
first, second = small[0], small[1]
|
|
262
|
+
length = second & 0x7f
|
|
263
|
+
if length == 126:
|
|
264
|
+
self._read_exact(sock, memoryview(small)[:2])
|
|
265
|
+
length = struct.unpack('>H', small[:2])[0]
|
|
266
|
+
elif length == 127:
|
|
267
|
+
self._read_exact(sock, memoryview(small))
|
|
268
|
+
length = struct.unpack('>Q', small)[0]
|
|
269
|
+
mask = bytearray(4)
|
|
270
|
+
if second & 0x80:
|
|
271
|
+
self._read_exact(sock, memoryview(mask))
|
|
272
|
+
opcode = first & 0x0f
|
|
273
|
+
if opcode == 0x8:
|
|
274
|
+
raise ConnectionError('WebRTC tap closed')
|
|
275
|
+
if opcode in (0x9, 0xA):
|
|
276
|
+
self._read_exact(sock, memoryview(bytearray(length)))
|
|
277
|
+
continue
|
|
278
|
+
if total + length > len(self.buf):
|
|
279
|
+
self.buf.extend(bytearray(total + length - len(self.buf)))
|
|
280
|
+
self._read_exact(sock, memoryview(self.buf)[total:total + length])
|
|
281
|
+
if second & 0x80:
|
|
282
|
+
unmask(self.buf, total, length, mask)
|
|
283
|
+
total += length
|
|
284
|
+
if first & 0x80:
|
|
285
|
+
return memoryview(self.buf)[:total]
|
|
286
|
+
|
|
287
|
+
def request(self, timeout=2.0):
|
|
288
|
+
"""Ask the page for its newest frame. Returns the raw message or None without a tap."""
|
|
289
|
+
with self.lock:
|
|
290
|
+
sock = self.sock
|
|
291
|
+
if sock is None:
|
|
292
|
+
return None
|
|
293
|
+
try:
|
|
294
|
+
sock.settimeout(timeout)
|
|
295
|
+
sock.sendall(b'\x81\x00') # empty text frame; servers must not mask
|
|
296
|
+
return self._read_message(sock)
|
|
297
|
+
except (OSError, ConnectionError) as e:
|
|
298
|
+
logger.info(f'WebRTC tap lost: {e}')
|
|
299
|
+
sock.close()
|
|
300
|
+
if self.sock is sock:
|
|
301
|
+
self.sock = None
|
|
302
|
+
return None
|
|
303
|
+
|
|
304
|
+
def disconnect(self):
|
|
305
|
+
with self.lock:
|
|
306
|
+
if self.sock is not None:
|
|
307
|
+
self.sock.close()
|
|
308
|
+
self.sock = None
|
|
309
|
+
|
|
310
|
+
def close(self):
|
|
311
|
+
self.closed = True
|
|
312
|
+
try:
|
|
313
|
+
self.listener.close()
|
|
314
|
+
except OSError:
|
|
315
|
+
pass
|
|
316
|
+
with self.lock:
|
|
317
|
+
if self.sock is not None:
|
|
318
|
+
self.sock.close()
|
|
319
|
+
self.sock = None
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def unmask(buf, start, length, mask):
|
|
323
|
+
data = np.frombuffer(buf, np.uint8, length, start)
|
|
324
|
+
words = length // 4
|
|
325
|
+
if words:
|
|
326
|
+
data[:words * 4].view(np.uint32)[:] ^= np.frombuffer(bytes(mask), np.uint32)[0]
|
|
327
|
+
for i in range(words * 4, length):
|
|
328
|
+
data[i] ^= mask[i % 4]
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def parse_message(message):
|
|
332
|
+
"""Return (status, frame_bgr, content_rect, element_rect) from a tap message."""
|
|
333
|
+
header = np.frombuffer(message, np.uint32, 12)
|
|
334
|
+
if len(message) < HEADER_SIZE or header[0] != MAGIC:
|
|
335
|
+
return STATUS_NO_FRAME, None, None, None
|
|
336
|
+
status = int(header[1])
|
|
337
|
+
if status != STATUS_FRAME:
|
|
338
|
+
return status, None, None, None
|
|
339
|
+
w, h, fmt = int(header[2]), int(header[3]), int(header[4])
|
|
340
|
+
offsets = [int(header[5 + i * 2]) + HEADER_SIZE for i in range(3)]
|
|
341
|
+
strides = [int(header[6 + i * 2]) for i in range(3)]
|
|
342
|
+
rects = np.frombuffer(message, np.float32, 8, 48)
|
|
343
|
+
return status, to_bgr(message, w, h, fmt, offsets, strides), tuple(rects[:4]), tuple(rects[4:])
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
def to_bgr(message, w, h, fmt, offsets, strides):
|
|
347
|
+
def plane(i, rows, row_bytes):
|
|
348
|
+
return np.frombuffer(message, np.uint8, rows * strides[i], offsets[i]).reshape(rows, strides[i])[:, :row_bytes]
|
|
349
|
+
|
|
350
|
+
if fmt == FORMAT_BGRA:
|
|
351
|
+
return cv2.cvtColor(plane(0, h, w * 4).reshape(h, w, 4), cv2.COLOR_BGRA2BGR)
|
|
352
|
+
if fmt == FORMAT_I420:
|
|
353
|
+
cw, ch = (w + 1) // 2, (h + 1) // 2
|
|
354
|
+
if w % 2 == 0 and h % 2 == 0 and strides == [w, cw, cw] and offsets[1] == offsets[0] + w * h \
|
|
355
|
+
and offsets[2] == offsets[1] + cw * ch:
|
|
356
|
+
yuv = np.frombuffer(message, np.uint8, w * h * 3 // 2, offsets[0]).reshape(h * 3 // 2, w)
|
|
357
|
+
else:
|
|
358
|
+
u = np.ascontiguousarray(plane(1, ch, cw))[:h // 2, :w // 2]
|
|
359
|
+
v = np.ascontiguousarray(plane(2, ch, cw))[:h // 2, :w // 2]
|
|
360
|
+
h2, w2 = h // 2 * 2, w // 2 * 2
|
|
361
|
+
yuv = np.concatenate([plane(0, h2, w2), u.reshape(-1, w2), v.reshape(-1, w2)])
|
|
362
|
+
return cv2.cvtColor(yuv, cv2.COLOR_YUV2BGR_I420)
|
|
363
|
+
if fmt == FORMAT_NV12:
|
|
364
|
+
h2, w2 = h // 2 * 2, w // 2 * 2
|
|
365
|
+
y = plane(0, h2, w2)
|
|
366
|
+
uv = plane(1, h2 // 2, w2).reshape(h2 // 2, w2 // 2, 2)
|
|
367
|
+
return cv2.cvtColorTwoPlane(y, uv, cv2.COLOR_YUV2BGR_NV12)
|
|
368
|
+
raise ValueError(f'unsupported WebRTC frame format {fmt}')
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def place_in_viewport(frame, content_rect, element_rect, viewport_size, offset=(0, 0)):
|
|
372
|
+
"""Draw the video frame where the page shows it, on a black viewport-sized image.
|
|
373
|
+
|
|
374
|
+
content_rect is where the whole video content is drawn (it can extend past the element with
|
|
375
|
+
object-fit: cover); element_rect clips it. Both are CSS pixels of the frame's viewport;
|
|
376
|
+
offset moves them into the top-level page (iframes).
|
|
377
|
+
"""
|
|
378
|
+
vw, vh = viewport_size
|
|
379
|
+
fh, fw = frame.shape[:2]
|
|
380
|
+
cx, cy, cw, ch = content_rect
|
|
381
|
+
cx, cy = cx + offset[0], cy + offset[1]
|
|
382
|
+
ex, ey, ew, eh = element_rect
|
|
383
|
+
ex, ey = ex + offset[0], ey + offset[1]
|
|
384
|
+
if cw <= 0 or ch <= 0:
|
|
385
|
+
return None
|
|
386
|
+
if (fw, fh) == (vw, vh) and abs(cx) < 0.5 and abs(cy) < 0.5 and abs(cw - vw) < 0.5 and abs(ch - vh) < 0.5:
|
|
387
|
+
return frame
|
|
388
|
+
left, top = max(cx, ex, 0), max(cy, ey, 0)
|
|
389
|
+
right, bottom = min(cx + cw, ex + ew, vw), min(cy + ch, ey + eh, vh)
|
|
390
|
+
x0, y0, x1, y1 = int(round(left)), int(round(top)), int(round(right)), int(round(bottom))
|
|
391
|
+
if x1 <= x0 or y1 <= y0:
|
|
392
|
+
return None
|
|
393
|
+
sx, sy = fw / cw, fh / ch
|
|
394
|
+
src = frame[max(0, int((y0 - cy) * sy)):min(fh, int(np.ceil((y1 - cy) * sy))),
|
|
395
|
+
max(0, int((x0 - cx) * sx)):min(fw, int(np.ceil((x1 - cx) * sx)))]
|
|
396
|
+
if src.size == 0:
|
|
397
|
+
return None
|
|
398
|
+
out = np.zeros((vh, vw, 3), np.uint8)
|
|
399
|
+
if src.shape[1] == x1 - x0 and src.shape[0] == y1 - y0:
|
|
400
|
+
out[y0:y1, x0:x1] = src
|
|
401
|
+
else:
|
|
402
|
+
shrinking = src.shape[1] > x1 - x0
|
|
403
|
+
out[y0:y1, x0:x1] = cv2.resize(src, (x1 - x0, y1 - y0),
|
|
404
|
+
interpolation=cv2.INTER_AREA if shrinking else cv2.INTER_LINEAR)
|
|
405
|
+
return out
|
|
@@ -59,7 +59,8 @@ class FlowLayout(QLayout):
|
|
|
59
59
|
def minimumSize(self) -> QSize:
|
|
60
60
|
size = QSize()
|
|
61
61
|
for item in self._items:
|
|
62
|
-
|
|
62
|
+
if not item.isEmpty():
|
|
63
|
+
size = size.expandedTo(item.minimumSize())
|
|
63
64
|
margins = self.contentsMargins()
|
|
64
65
|
return size + QSize(margins.left() + margins.right(), margins.top() + margins.bottom())
|
|
65
66
|
|
|
@@ -68,8 +69,8 @@ class FlowLayout(QLayout):
|
|
|
68
69
|
area = rect.adjusted(margins.left(), margins.top(), -margins.right(), -margins.bottom())
|
|
69
70
|
x, y, line_height = area.x(), area.y(), 0
|
|
70
71
|
for item in self._items:
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
# Layout activation can precede the widget's show event.
|
|
73
|
+
if item.isEmpty():
|
|
73
74
|
continue
|
|
74
75
|
hint = item.sizeHint()
|
|
75
76
|
if x + hint.width() > area.right() + 1 and line_height > 0:
|