matter-all-in-one-addon 2.1.2 → 2.3.1
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.
- package/README.md +71 -274
- package/dist/camera/ai/camera-ai-detector.d.ts +6 -4
- package/dist/camera/ai/camera-ai-detector.js +62 -36
- package/dist/camera/ai/camera-ai-detector.js.map +1 -1
- package/dist/camera/ai/camera-diagnostics.d.ts +48 -0
- package/dist/camera/ai/camera-diagnostics.js +41 -0
- package/dist/camera/ai/camera-diagnostics.js.map +1 -0
- package/dist/camera/ai/diagnostics-auth.d.ts +2 -0
- package/dist/camera/ai/diagnostics-auth.js +13 -0
- package/dist/camera/ai/diagnostics-auth.js.map +1 -0
- package/dist/camera/camera-capabilities.js +7 -6
- package/dist/camera/camera-capabilities.js.map +1 -1
- package/dist/camera/camera-entity-control.d.ts +12 -0
- package/dist/camera/camera-entity-control.js +24 -0
- package/dist/camera/camera-entity-control.js.map +1 -0
- package/dist/camera/camera-source-resolver.d.ts +16 -0
- package/dist/camera/camera-source-resolver.js +123 -0
- package/dist/camera/camera-source-resolver.js.map +1 -1
- package/dist/camera/camera-types.d.ts +2 -0
- package/dist/camera/cameraui/cameraui-homekit-bridge.js +26 -6
- package/dist/camera/cameraui/cameraui-homekit-bridge.js.map +1 -1
- package/dist/camera/homekit/ffmpeg-helper.d.ts +1 -4
- package/dist/camera/homekit/ffmpeg-helper.js +65 -27
- package/dist/camera/homekit/ffmpeg-helper.js.map +1 -1
- package/dist/camera/homekit/hevc/bootstrap.d.ts +9 -0
- package/dist/camera/homekit/hevc/bootstrap.js +47 -0
- package/dist/camera/homekit/hevc/bootstrap.js.map +1 -0
- package/dist/camera/homekit/hevc/hevc-recording.d.ts +2 -0
- package/dist/camera/homekit/hevc/hevc-recording.js +70 -33
- package/dist/camera/homekit/hevc/hevc-recording.js.map +1 -1
- package/dist/camera/homekit/hevc/multi-tier-rtp.d.ts +15 -1
- package/dist/camera/homekit/hevc/multi-tier-rtp.js +229 -64
- package/dist/camera/homekit/hevc/multi-tier-rtp.js.map +1 -1
- package/dist/camera/homekit/hevc/recording-output.d.ts +2 -0
- package/dist/camera/homekit/hevc/recording-output.js +33 -0
- package/dist/camera/homekit/hevc/recording-output.js.map +1 -0
- package/dist/camera/homekit/hevc/sframe-rtp.d.ts +2 -0
- package/dist/camera/homekit/hevc/sframe-rtp.js +38 -4
- package/dist/camera/homekit/hevc/sframe-rtp.js.map +1 -1
- package/dist/camera/homekit/hevc/sframe.d.ts +11 -1
- package/dist/camera/homekit/hevc/sframe.js +195 -23
- package/dist/camera/homekit/hevc/sframe.js.map +1 -1
- package/dist/camera/homekit/hevc/webrtc-session.d.ts +17 -3
- package/dist/camera/homekit/hevc/webrtc-session.js +262 -63
- package/dist/camera/homekit/hevc/webrtc-session.js.map +1 -1
- package/dist/camera/homekit/homekit-camera-recording.delegate.d.ts +5 -0
- package/dist/camera/homekit/homekit-camera-recording.delegate.js +89 -111
- package/dist/camera/homekit/homekit-camera-recording.delegate.js.map +1 -1
- package/dist/camera/homekit/homekit-camera-stream.delegate.d.ts +10 -2
- package/dist/camera/homekit/homekit-camera-stream.delegate.js +339 -310
- package/dist/camera/homekit/homekit-camera-stream.delegate.js.map +1 -1
- package/dist/camera/homekit/homekit-camera.accessory.d.ts +42 -2
- package/dist/camera/homekit/homekit-camera.accessory.js +255 -162
- package/dist/camera/homekit/homekit-camera.accessory.js.map +1 -1
- package/dist/camera/homekit/live-view-telemetry.d.ts +4 -0
- package/dist/camera/homekit/live-view-telemetry.js.map +1 -1
- package/dist/camera/homekit/media-policy.d.ts +25 -0
- package/dist/camera/homekit/media-policy.js +102 -0
- package/dist/camera/homekit/media-policy.js.map +1 -0
- package/dist/camera/homekit/route-address.d.ts +2 -0
- package/dist/camera/homekit/route-address.js +27 -0
- package/dist/camera/homekit/route-address.js.map +1 -0
- package/dist/camera/homekit/rtp-relay.d.ts +21 -0
- package/dist/camera/homekit/rtp-relay.js +112 -0
- package/dist/camera/homekit/rtp-relay.js.map +1 -0
- package/dist/camera/homekit/startup-timing.d.ts +8 -0
- package/dist/camera/homekit/startup-timing.js +14 -0
- package/dist/camera/homekit/startup-timing.js.map +1 -0
- package/dist/camera/motion/ffmpeg-motion-detector.d.ts +10 -0
- package/dist/camera/motion/ffmpeg-motion-detector.js +126 -77
- package/dist/camera/motion/ffmpeg-motion-detector.js.map +1 -1
- package/dist/camera/scrypted/scrypted-stream-validator.d.ts +1 -1
- package/dist/camera/scrypted/scrypted-stream-validator.js +8 -3
- package/dist/camera/scrypted/scrypted-stream-validator.js.map +1 -1
- package/dist/camera/source-adapter.d.ts +132 -0
- package/dist/camera/source-adapter.js +282 -0
- package/dist/camera/source-adapter.js.map +1 -0
- package/dist/converters/vacuum.converter.d.ts +3 -2
- package/dist/converters/vacuum.converter.js +29 -4
- package/dist/converters/vacuum.converter.js.map +1 -1
- package/dist/device-profiles.d.ts +3 -3
- package/dist/device-profiles.js +26 -6
- package/dist/device-profiles.js.map +1 -1
- package/dist/device-registry.d.ts +1 -0
- package/dist/device-registry.js +11 -3
- package/dist/device-registry.js.map +1 -1
- package/dist/entities/base.entity.js +3 -1
- package/dist/entities/base.entity.js.map +1 -1
- package/dist/entities/camera.entity.d.ts +2 -0
- package/dist/entities/camera.entity.js +40 -1
- package/dist/entities/camera.entity.js.map +1 -1
- package/dist/entities/composite-device.entity.js +2 -1
- package/dist/entities/composite-device.entity.js.map +1 -1
- package/dist/entities/energy_tariff.entity.js +21 -8
- package/dist/entities/energy_tariff.entity.js.map +1 -1
- package/dist/entities/vacuum.entity.d.ts +8 -0
- package/dist/entities/vacuum.entity.js +300 -36
- package/dist/entities/vacuum.entity.js.map +1 -1
- package/dist/frontend/assets/index-Bka3TVAQ.js +21 -0
- package/dist/frontend/assets/{index-CJdlkpIy.css → index-NrzHqycm.css} +1 -1
- package/dist/frontend/index.html +2 -2
- package/dist/hap/hap-generic-accessory.d.ts +3 -1
- package/dist/hap/hap-generic-accessory.js +50 -0
- package/dist/hap/hap-generic-accessory.js.map +1 -1
- package/dist/homeAssistant.d.ts +13 -0
- package/dist/homeAssistant.js +54 -13
- package/dist/homeAssistant.js.map +1 -1
- package/dist/homekit.compat.d.ts +2 -1
- package/dist/homekit.compat.js +4 -1
- package/dist/homekit.compat.js.map +1 -1
- package/dist/platform.d.ts +19 -7
- package/dist/platform.js +865 -587
- package/dist/platform.js.map +1 -1
- package/dist/proxy.js +1 -11
- package/dist/proxy.js.map +1 -1
- package/dist/utils/atomic-json-store.d.ts +5 -0
- package/dist/utils/atomic-json-store.js +31 -0
- package/dist/utils/atomic-json-store.js.map +1 -0
- package/dist/utils/ha-entity-names.d.ts +21 -0
- package/dist/utils/ha-entity-names.js +26 -0
- package/dist/utils/ha-entity-names.js.map +1 -0
- package/package.json +22 -19
- package/vendor/hap-nodejs/LICENSE +176 -0
- package/vendor/hap-nodejs/MIAO.md +5 -0
- package/vendor/hap-nodejs/PATCH.md +37 -0
- package/vendor/hap-nodejs/README.md +86 -0
- package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.d.ts +2 -0
- package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.js +128 -0
- package/vendor/hap-nodejs/dist/accessories/AirConditioner_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.d.ts +2 -0
- package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.js +159 -0
- package/vendor/hap-nodejs/dist/accessories/AppleTVRemote_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Camera_accessory.d.ts +2 -0
- package/vendor/hap-nodejs/dist/accessories/Camera_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Camera_accessory.js +545 -0
- package/vendor/hap-nodejs/dist/accessories/Camera_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Fan_accessory.d.ts +2 -0
- package/vendor/hap-nodejs/dist/accessories/Fan_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Fan_accessory.js +74 -0
- package/vendor/hap-nodejs/dist/accessories/Fan_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.d.ts +2 -0
- package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.js +78 -0
- package/vendor/hap-nodejs/dist/accessories/GarageDoorOpener_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.d.ts +2 -0
- package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.js +106 -0
- package/vendor/hap-nodejs/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Light_accessory.d.ts +2 -0
- package/vendor/hap-nodejs/dist/accessories/Light_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Light_accessory.js +145 -0
- package/vendor/hap-nodejs/dist/accessories/Light_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Lock_accessory.d.ts +2 -0
- package/vendor/hap-nodejs/dist/accessories/Lock_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Lock_accessory.js +76 -0
- package/vendor/hap-nodejs/dist/accessories/Lock_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.d.ts +2 -0
- package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.js +45 -0
- package/vendor/hap-nodejs/dist/accessories/MotionSensor_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.d.ts +2 -0
- package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.js +79 -0
- package/vendor/hap-nodejs/dist/accessories/Outlet_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.d.ts +2 -0
- package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.js +44 -0
- package/vendor/hap-nodejs/dist/accessories/SmartSpeaker_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.d.ts +2 -0
- package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.js +128 -0
- package/vendor/hap-nodejs/dist/accessories/Sprinkler_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/TV_accessory.d.ts +2 -0
- package/vendor/hap-nodejs/dist/accessories/TV_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/TV_accessory.js +101 -0
- package/vendor/hap-nodejs/dist/accessories/TV_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.d.ts +2 -0
- package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.js +44 -0
- package/vendor/hap-nodejs/dist/accessories/TemperatureSensor_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.d.ts +3 -0
- package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.js +17 -0
- package/vendor/hap-nodejs/dist/accessories/Wi-FiRouter_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.d.ts +3 -0
- package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.js +19 -0
- package/vendor/hap-nodejs/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.d.ts +25 -0
- package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.js +145 -0
- package/vendor/hap-nodejs/dist/accessories/gstreamer-audioProducer.js.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/types.d.ts +78 -0
- package/vendor/hap-nodejs/dist/accessories/types.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/accessories/types.js +88 -0
- package/vendor/hap-nodejs/dist/accessories/types.js.map +1 -0
- package/vendor/hap-nodejs/dist/index.d.ts +50 -0
- package/vendor/hap-nodejs/dist/index.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/index.js +54 -0
- package/vendor/hap-nodejs/dist/index.js.map +1 -0
- package/vendor/hap-nodejs/dist/internal-types.d.ts +76 -0
- package/vendor/hap-nodejs/dist/internal-types.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/internal-types.js +80 -0
- package/vendor/hap-nodejs/dist/internal-types.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/Accessory.d.ts +521 -0
- package/vendor/hap-nodejs/dist/lib/Accessory.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/Accessory.js +1762 -0
- package/vendor/hap-nodejs/dist/lib/Accessory.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/Advertiser.d.ts +190 -0
- package/vendor/hap-nodejs/dist/lib/Advertiser.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/Advertiser.js +592 -0
- package/vendor/hap-nodejs/dist/lib/Advertiser.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/Bridge.d.ts +12 -0
- package/vendor/hap-nodejs/dist/lib/Bridge.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/Bridge.js +19 -0
- package/vendor/hap-nodejs/dist/lib/Bridge.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/Characteristic.d.ts +1768 -0
- package/vendor/hap-nodejs/dist/lib/Characteristic.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/Characteristic.js +2532 -0
- package/vendor/hap-nodejs/dist/lib/Characteristic.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/HAPServer.d.ts +299 -0
- package/vendor/hap-nodejs/dist/lib/HAPServer.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/HAPServer.js +968 -0
- package/vendor/hap-nodejs/dist/lib/HAPServer.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/Service.d.ts +598 -0
- package/vendor/hap-nodejs/dist/lib/Service.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/Service.js +797 -0
- package/vendor/hap-nodejs/dist/lib/Service.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.d.ts +102 -0
- package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.js +317 -0
- package/vendor/hap-nodejs/dist/lib/camera/CMAFIngest.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.d.ts +38 -0
- package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.js +174 -0
- package/vendor/hap-nodejs/dist/lib/camera/HDSSnapshotTransport.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.d.ts +59 -0
- package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.js +267 -0
- package/vendor/hap-nodejs/dist/lib/camera/RTPProxy.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.d.ts +379 -0
- package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.js +1021 -0
- package/vendor/hap-nodejs/dist/lib/camera/RTPStreamManagement.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.d.ts +325 -0
- package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.js +800 -0
- package/vendor/hap-nodejs/dist/lib/camera/RecordingManagement.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.d.ts +20 -0
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.js +48 -0
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoCredentials.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.d.ts +618 -0
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.js +911 -0
- package/vendor/hap-nodejs/dist/lib/camera/SecureVideoTypes.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/index.d.ts +8 -0
- package/vendor/hap-nodejs/dist/lib/camera/index.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/camera/index.js +11 -0
- package/vendor/hap-nodejs/dist/lib/camera/index.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.d.ts +452 -0
- package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.js +868 -0
- package/vendor/hap-nodejs/dist/lib/controller/AdaptiveLightingController.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/controller/CameraController.d.ts +410 -0
- package/vendor/hap-nodejs/dist/lib/controller/CameraController.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/controller/CameraController.js +658 -0
- package/vendor/hap-nodejs/dist/lib/controller/CameraController.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/controller/Controller.d.ts +197 -0
- package/vendor/hap-nodejs/dist/lib/controller/Controller.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/controller/Controller.js +32 -0
- package/vendor/hap-nodejs/dist/lib/controller/Controller.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.d.ts +59 -0
- package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.js +102 -0
- package/vendor/hap-nodejs/dist/lib/controller/DoorbellController.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/controller/RemoteController.d.ts +434 -0
- package/vendor/hap-nodejs/dist/lib/controller/RemoteController.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/controller/RemoteController.js +1178 -0
- package/vendor/hap-nodejs/dist/lib/controller/RemoteController.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.d.ts +380 -0
- package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.js +947 -0
- package/vendor/hap-nodejs/dist/lib/controller/SecureVideoController.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/controller/index.d.ts +7 -0
- package/vendor/hap-nodejs/dist/lib/controller/index.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/controller/index.js +10 -0
- package/vendor/hap-nodejs/dist/lib/controller/index.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.d.ts +73 -0
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.js +205 -0
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamManagement.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.d.ts +186 -0
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.js +880 -0
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamParser.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.d.ts +351 -0
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.js +878 -0
- package/vendor/hap-nodejs/dist/lib/datastream/DataStreamServer.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/datastream/index.d.ts +4 -0
- package/vendor/hap-nodejs/dist/lib/datastream/index.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/datastream/index.js +7 -0
- package/vendor/hap-nodejs/dist/lib/datastream/index.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.d.ts +2245 -0
- package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.js +4957 -0
- package/vendor/hap-nodejs/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.d.ts +584 -0
- package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.js +1518 -0
- package/vendor/hap-nodejs/dist/lib/definitions/ServiceDefinitions.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.d.ts +34 -0
- package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.js +624 -0
- package/vendor/hap-nodejs/dist/lib/definitions/generate-definitions.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.d.ts +22 -0
- package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.js +734 -0
- package/vendor/hap-nodejs/dist/lib/definitions/generator-configuration.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/definitions/index.d.ts +3 -0
- package/vendor/hap-nodejs/dist/lib/definitions/index.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/definitions/index.js +6 -0
- package/vendor/hap-nodejs/dist/lib/definitions/index.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/gen/HomeKit.d.ts +8 -0
- package/vendor/hap-nodejs/dist/lib/gen/HomeKit.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/gen/HomeKit.js +9 -0
- package/vendor/hap-nodejs/dist/lib/gen/HomeKit.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.d.ts +91 -0
- package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.js +311 -0
- package/vendor/hap-nodejs/dist/lib/model/AccessoryInfo.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.d.ts +46 -0
- package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.js +277 -0
- package/vendor/hap-nodejs/dist/lib/model/ControllerStorage.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.d.ts +75 -0
- package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.js +190 -0
- package/vendor/hap-nodejs/dist/lib/model/HAPFileStorage.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/model/HAPStorage.d.ts +26 -0
- package/vendor/hap-nodejs/dist/lib/model/HAPStorage.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/model/HAPStorage.js +79 -0
- package/vendor/hap-nodejs/dist/lib/model/HAPStorage.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.d.ts +33 -0
- package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.js +114 -0
- package/vendor/hap-nodejs/dist/lib/model/IdentifierCache.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.d.ts +83 -0
- package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.js +127 -0
- package/vendor/hap-nodejs/dist/lib/tv/AccessControlManagement.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/checkName.d.ts +8 -0
- package/vendor/hap-nodejs/dist/lib/util/checkName.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/checkName.js +28 -0
- package/vendor/hap-nodejs/dist/lib/util/checkName.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/clone.d.ts +7 -0
- package/vendor/hap-nodejs/dist/lib/util/clone.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/clone.js +22 -0
- package/vendor/hap-nodejs/dist/lib/util/clone.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/color-utils.d.ts +18 -0
- package/vendor/hap-nodejs/dist/lib/util/color-utils.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/color-utils.js +442 -0
- package/vendor/hap-nodejs/dist/lib/util/color-utils.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/eventedhttp.d.ts +251 -0
- package/vendor/hap-nodejs/dist/lib/util/eventedhttp.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/eventedhttp.js +714 -0
- package/vendor/hap-nodejs/dist/lib/util/eventedhttp.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/hapCrypto.d.ts +50 -0
- package/vendor/hap-nodejs/dist/lib/util/hapCrypto.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/hapCrypto.js +185 -0
- package/vendor/hap-nodejs/dist/lib/util/hapCrypto.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/hapStatusError.d.ts +16 -0
- package/vendor/hap-nodejs/dist/lib/util/hapStatusError.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/hapStatusError.js +29 -0
- package/vendor/hap-nodejs/dist/lib/util/hapStatusError.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/net-utils.d.ts +21 -0
- package/vendor/hap-nodejs/dist/lib/util/net-utils.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/net-utils.js +79 -0
- package/vendor/hap-nodejs/dist/lib/util/net-utils.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/once.d.ts +7 -0
- package/vendor/hap-nodejs/dist/lib/util/once.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/once.js +22 -0
- package/vendor/hap-nodejs/dist/lib/util/once.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/promise-utils.d.ts +14 -0
- package/vendor/hap-nodejs/dist/lib/util/promise-utils.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/promise-utils.js +29 -0
- package/vendor/hap-nodejs/dist/lib/util/promise-utils.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/request-util.d.ts +36 -0
- package/vendor/hap-nodejs/dist/lib/util/request-util.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/request-util.js +108 -0
- package/vendor/hap-nodejs/dist/lib/util/request-util.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/time.d.ts +9 -0
- package/vendor/hap-nodejs/dist/lib/util/time.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/time.js +23 -0
- package/vendor/hap-nodejs/dist/lib/util/time.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/tlv.d.ts +90 -0
- package/vendor/hap-nodejs/dist/lib/util/tlv.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/tlv.js +318 -0
- package/vendor/hap-nodejs/dist/lib/util/tlv.js.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/uuid.d.ts +23 -0
- package/vendor/hap-nodejs/dist/lib/util/uuid.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/lib/util/uuid.js +78 -0
- package/vendor/hap-nodejs/dist/lib/util/uuid.js.map +1 -0
- package/vendor/hap-nodejs/dist/types.d.ts +276 -0
- package/vendor/hap-nodejs/dist/types.d.ts.map +1 -0
- package/vendor/hap-nodejs/dist/types.js +11 -0
- package/vendor/hap-nodejs/dist/types.js.map +1 -0
- package/vendor/hap-nodejs/package.json +53 -0
- package/vendor/hap-nodejs/src/lib/util/hapCrypto.ts +208 -0
- package/dist/frontend/assets/index-8tQZaFmi.js +0 -28
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { RtpDatagramRelay } from "./rtp-relay.js";
|
|
2
|
+
import { StreamStartupTiming } from "./startup-timing.js";
|
|
3
|
+
import { routeAddress } from "./route-address.js";
|
|
4
|
+
import { CameraSourceAdapter } from "../source-adapter.js";
|
|
5
|
+
import { h264AudioPlan, h264VideoPlan, verifiedH264Encoder, } from "./media-policy.js";
|
|
1
6
|
import { EventEmitter } from "node:events";
|
|
2
7
|
import fs from "node:fs/promises";
|
|
3
8
|
import fsSync from "node:fs";
|
|
@@ -6,7 +11,7 @@ import { spawn } from "node:child_process";
|
|
|
6
11
|
import dgram from "node:dgram";
|
|
7
12
|
import { isIPv4, isIPv6 } from "node:net";
|
|
8
13
|
import { CameraSourceResolver } from "../camera-source-resolver.js";
|
|
9
|
-
import { getFfmpegVersion, resolveFfmpegPath,
|
|
14
|
+
import { getFfmpegVersion, resolveFfmpegPath, supportsFdkAac, checkAudioPassthroughCompatibility, } from "./ffmpeg-helper.js";
|
|
10
15
|
import { createSessionTelemetry, finishSessionTelemetry, mergeFfmpegProgress, mergeFfmpegStreamHeader, retainRecentSessions, sanitizeDiagnosticText, } from "./live-view-telemetry.js";
|
|
11
16
|
export const FALLBACK_JPEG_BUFFER = Buffer.from("/9j/4AAQSkZJRgABAgAAAQABAAD//gAPTGF2YzYwLjMuMTAwAP/bAEMACAYGBwYHCAgICAgICQkJCgoKCQkJCQoKCgoKCgwMDAoKCgoKCgoMDAwMDQ4NDQ0MDQ4ODw8PEhIRERUVFRkZH//EAEwAAQEAAAAAAAAAAAAAAAAAAAAHAQEBAAAAAAAAAAAAAAAAAAAAARABAAAAAAAAAAAAAAAAAAAAABEBAAAAAAAAAAAAAAAAAAAAAP/AABEIAPABQAMBIgACEQADEQD/2gAMAwEAAhEDEQA/AI2AoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//9k=", "base64");
|
|
12
17
|
function isJpeg(buffer) {
|
|
@@ -147,6 +152,7 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
147
152
|
entityId;
|
|
148
153
|
capabilities;
|
|
149
154
|
streamSource;
|
|
155
|
+
record;
|
|
150
156
|
activeSessions = new Map();
|
|
151
157
|
/**
|
|
152
158
|
* Watchdog timers for orphaned prepareStream sessions.
|
|
@@ -173,12 +179,13 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
173
179
|
}
|
|
174
180
|
isTakingSnapshot = false;
|
|
175
181
|
lastSnapshotTime = 0;
|
|
176
|
-
constructor(platform, entityId, capabilities, streamSource) {
|
|
182
|
+
constructor(platform, entityId, capabilities, streamSource, record) {
|
|
177
183
|
super();
|
|
178
184
|
this.platform = platform;
|
|
179
185
|
this.entityId = entityId;
|
|
180
186
|
this.capabilities = capabilities;
|
|
181
187
|
this.streamSource = streamSource;
|
|
188
|
+
this.record = record;
|
|
182
189
|
this.loadPersistedSnapshot();
|
|
183
190
|
}
|
|
184
191
|
isTapoC120() {
|
|
@@ -212,7 +219,10 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
212
219
|
if (/wyze/i.test(fullText))
|
|
213
220
|
return false;
|
|
214
221
|
const isEzvizToken = (s) => /(?:\bezviz\b|\bh6c\b|4661fae4|patio[-_ ]?trasero|ezviz[-_ ]?patio)/i.test(s);
|
|
215
|
-
return isEzvizToken(model) ||
|
|
222
|
+
return (isEzvizToken(model) ||
|
|
223
|
+
isEzvizToken(entityId) ||
|
|
224
|
+
isEzvizToken(name) ||
|
|
225
|
+
isEzvizToken(sourceUrl));
|
|
216
226
|
}
|
|
217
227
|
isWyze() {
|
|
218
228
|
const sourceUrl = (this.getCleanSourceUrl() || "").toLowerCase();
|
|
@@ -220,7 +230,10 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
220
230
|
const model = String(this.streamSource?.metadata?.model || "").toLowerCase();
|
|
221
231
|
const entityId = this.entityId.toLowerCase();
|
|
222
232
|
const isWyzeToken = (s) => /(?:\bwyze\b|cba17b87)/i.test(s);
|
|
223
|
-
return isWyzeToken(model) ||
|
|
233
|
+
return (isWyzeToken(model) ||
|
|
234
|
+
isWyzeToken(entityId) ||
|
|
235
|
+
isWyzeToken(name) ||
|
|
236
|
+
isWyzeToken(sourceUrl));
|
|
224
237
|
}
|
|
225
238
|
/** Diagnostics only: never returns URLs, FFmpeg arguments, tokens, or SRTP material. */
|
|
226
239
|
getLiveViewTelemetry() {
|
|
@@ -285,6 +298,8 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
285
298
|
output,
|
|
286
299
|
fallbackReason,
|
|
287
300
|
});
|
|
301
|
+
if (session.startup)
|
|
302
|
+
session.telemetry.startup = session.startup;
|
|
288
303
|
}
|
|
289
304
|
finishTelemetry(session, state, error) {
|
|
290
305
|
if (!session.telemetry || session.telemetry.state !== "active")
|
|
@@ -298,6 +313,7 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
298
313
|
return;
|
|
299
314
|
if (/^Output #\d+/i.test(line.trim())) {
|
|
300
315
|
session.ffmpegOutputHeaderSeen = true;
|
|
316
|
+
session.startup?.mark("T4");
|
|
301
317
|
return;
|
|
302
318
|
}
|
|
303
319
|
const progress = mergeFfmpegProgress(session.telemetry.output, line);
|
|
@@ -314,7 +330,9 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
314
330
|
const buf = fsSync.readFileSync(snapPath);
|
|
315
331
|
if (isJpeg(buf) && buf.length > 2048) {
|
|
316
332
|
this.lastSnapshotBuffer = buf;
|
|
317
|
-
|
|
333
|
+
// A persisted snapshot can survive an add-on restart. Preserve its
|
|
334
|
+
// actual age instead of treating load time as capture time.
|
|
335
|
+
this.lastSnapshotTime = fsSync.statSync(snapPath).mtimeMs;
|
|
318
336
|
}
|
|
319
337
|
}
|
|
320
338
|
}
|
|
@@ -349,8 +367,16 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
349
367
|
: this.lastSnapshotBuffer;
|
|
350
368
|
if (isJpeg(selected) && selected !== FALLBACK_JPEG_BUFFER) {
|
|
351
369
|
this.lastSnapshotBuffer = selected;
|
|
352
|
-
|
|
353
|
-
|
|
370
|
+
// Cached/error fallbacks keep HomeKit responsive, but must not make
|
|
371
|
+
// old bytes appear newly captured or replace a newer disk snapshot.
|
|
372
|
+
if (source === "ha-fetch-snapshot" ||
|
|
373
|
+
source === "ha-fetch-png-converted" ||
|
|
374
|
+
source === "http-snapshot" ||
|
|
375
|
+
source === "http-png-converted" ||
|
|
376
|
+
source === "ffmpeg") {
|
|
377
|
+
this.lastSnapshotTime = Date.now();
|
|
378
|
+
void this.persistSnapshotToDisk(selected);
|
|
379
|
+
}
|
|
354
380
|
}
|
|
355
381
|
this.platform?.log?.notice?.(`[HomeKitCamera][${this.entityId}] Snapshot source=${source} bytes=${selected.length} duration=${Date.now() - started}ms validJpeg=${isJpeg(selected)}`);
|
|
356
382
|
callback(undefined, selected);
|
|
@@ -453,7 +479,7 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
453
479
|
}
|
|
454
480
|
}
|
|
455
481
|
catch (error) {
|
|
456
|
-
this.platform?.log?.debug?.(`[HomeKitCamera][${this.entityId}] Snapshot HTTP failed: ${
|
|
482
|
+
this.platform?.log?.debug?.(`[HomeKitCamera][${this.entityId}] Snapshot HTTP failed: ${sanitizeDiagnosticText(error)}`);
|
|
457
483
|
}
|
|
458
484
|
}
|
|
459
485
|
const ffmpegPath = resolveFfmpegPath();
|
|
@@ -463,11 +489,8 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
463
489
|
return;
|
|
464
490
|
}
|
|
465
491
|
const args = ["-hide_banner", "-loglevel", "error"];
|
|
466
|
-
if (sourceUrl
|
|
467
|
-
|
|
468
|
-
this.isWyze() ||
|
|
469
|
-
this.isEzviz();
|
|
470
|
-
args.push("-probesize", isDemandingCam ? "1048576" : this.isTapoC120() ? "131072" : "65536", "-analyzeduration", isDemandingCam ? "1000000" : "0", "-rtsp_transport", "tcp", "-timeout", "3000000", "-fflags", "+nobuffer+flush_packets", "-flags", "low_delay");
|
|
492
|
+
if (/^rtsps?:\/\//.test(sourceUrl)) {
|
|
493
|
+
args.push("-probesize", "2097152", "-analyzeduration", "3000000", "-rtsp_transport", "tcp", "-timeout", "3000000", "-fflags", "+nobuffer+flush_packets", "-flags", "low_delay");
|
|
471
494
|
}
|
|
472
495
|
else if (sourceUrl.startsWith("http://") ||
|
|
473
496
|
sourceUrl.startsWith("https://")) {
|
|
@@ -504,7 +527,7 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
504
527
|
});
|
|
505
528
|
}
|
|
506
529
|
catch (error) {
|
|
507
|
-
this.platform?.log?.warn?.(`[HomeKitCamera][${this.entityId}] Snapshot fatal error: ${
|
|
530
|
+
this.platform?.log?.warn?.(`[HomeKitCamera][${this.entityId}] Snapshot fatal error: ${sanitizeDiagnosticText(error)}`);
|
|
508
531
|
finish("fatal-error", this.lastSnapshotBuffer);
|
|
509
532
|
}
|
|
510
533
|
}
|
|
@@ -517,7 +540,7 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
517
540
|
// Purge any zombie sessions (process died but Map entry survived) before
|
|
518
541
|
// setting up a new one — otherwise the old dead entry corrupts cleanup.
|
|
519
542
|
for (const [sid, s] of [...this.activeSessions.entries()]) {
|
|
520
|
-
if (
|
|
543
|
+
if (s.process && (s.process.killed || s.process.exitCode !== null)) {
|
|
521
544
|
this.platform?.log?.notice?.(`[HomeKitCamera][${this.entityId}] Purging zombie session=${sid} before new prepare`);
|
|
522
545
|
if (s.pipeController) {
|
|
523
546
|
try {
|
|
@@ -531,6 +554,9 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
531
554
|
}
|
|
532
555
|
catch { }
|
|
533
556
|
}
|
|
557
|
+
s.releaseReader?.();
|
|
558
|
+
s.videoRelay?.close();
|
|
559
|
+
s.audioRelay?.close();
|
|
534
560
|
this.activeSessions.delete(sid);
|
|
535
561
|
}
|
|
536
562
|
}
|
|
@@ -551,7 +577,7 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
551
577
|
]),
|
|
552
578
|
};
|
|
553
579
|
if (request.audio) {
|
|
554
|
-
const audioPort = localAudioPort ||
|
|
580
|
+
const audioPort = localAudioPort || localVideoPort + 1;
|
|
555
581
|
session.audioPort = request.audio.port;
|
|
556
582
|
session.localAudioPort = audioPort;
|
|
557
583
|
session.audioSsrc = CameraController.generateSynchronisationSource();
|
|
@@ -562,6 +588,18 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
562
588
|
]);
|
|
563
589
|
}
|
|
564
590
|
this.activeSessions.set(request.sessionID, session);
|
|
591
|
+
try {
|
|
592
|
+
session.videoRelay = await RtpDatagramRelay.create(request.targetAddress, request.video.port, () => session.startup?.mark("T5"));
|
|
593
|
+
if (request.audio)
|
|
594
|
+
session.audioRelay = await RtpDatagramRelay.create(request.targetAddress, request.audio.port, () => session.startup?.mark("T6"));
|
|
595
|
+
}
|
|
596
|
+
catch (error) {
|
|
597
|
+
session.videoRelay?.close();
|
|
598
|
+
session.audioRelay?.close();
|
|
599
|
+
session.releaseReader?.();
|
|
600
|
+
this.activeSessions.delete(session.sessionId);
|
|
601
|
+
throw error;
|
|
602
|
+
}
|
|
565
603
|
// Install watchdog timer: if startStream is never called by iOS (e.g. user cancelled
|
|
566
604
|
// live view before connection established), auto-clean the orphaned session after 45s.
|
|
567
605
|
const zombieTimer = setTimeout(() => {
|
|
@@ -569,6 +607,9 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
569
607
|
const s = this.activeSessions.get(request.sessionID);
|
|
570
608
|
if (s && !s.process) {
|
|
571
609
|
this.platform?.log?.warn?.(`[HomeKitCamera][${this.entityId}] [Session][${request.sessionID}] session-timeout: prepareStream completed but startStream was not called after ${HomeKitCameraStreamingDelegate.PREPARE_TIMEOUT_MS / 1000}s — clearing orphan session`);
|
|
610
|
+
s.releaseReader?.();
|
|
611
|
+
s.videoRelay?.close();
|
|
612
|
+
s.audioRelay?.close();
|
|
572
613
|
this.activeSessions.delete(request.sessionID);
|
|
573
614
|
if (this.activeSessions.size === 0) {
|
|
574
615
|
this.platform?.log?.notice?.(`[HomeKitCamera][${this.entityId}] [Session] session-end (cleared last orphan session)`);
|
|
@@ -585,24 +626,19 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
585
626
|
request.sourceAddress.startsWith("::ffff:")
|
|
586
627
|
? request.sourceAddress.slice("::ffff:".length)
|
|
587
628
|
: request.sourceAddress;
|
|
588
|
-
const addressOverride = request.
|
|
589
|
-
|
|
590
|
-
? sourceAddress
|
|
591
|
-
: detectPrimaryNetworkInterface()?.ip
|
|
592
|
-
: isIPv6(sourceAddress || "")
|
|
593
|
-
? sourceAddress
|
|
594
|
-
: undefined;
|
|
629
|
+
const addressOverride = await routeAddress(request.targetAddress, request.video.port);
|
|
630
|
+
session.localAddress = addressOverride;
|
|
595
631
|
const response = {
|
|
596
632
|
...(addressOverride ? { addressOverride } : {}),
|
|
597
633
|
video: {
|
|
598
|
-
port: localVideoPort,
|
|
634
|
+
port: session.videoRelay?.outputPort || localVideoPort,
|
|
599
635
|
ssrc: session.videoSsrc,
|
|
600
636
|
srtp_key: request.video.srtp_key,
|
|
601
637
|
srtp_salt: request.video.srtp_salt,
|
|
602
638
|
},
|
|
603
639
|
};
|
|
604
640
|
if (request.audio) {
|
|
605
|
-
const audioPort = session.localAudioPort || localAudioPort ||
|
|
641
|
+
const audioPort = session.localAudioPort || localAudioPort || localVideoPort + 1;
|
|
606
642
|
response.audio = {
|
|
607
643
|
port: audioPort,
|
|
608
644
|
ssrc: session.audioSsrc,
|
|
@@ -615,7 +651,7 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
615
651
|
callback(undefined, response);
|
|
616
652
|
}
|
|
617
653
|
catch (error) {
|
|
618
|
-
this.platform?.log?.warn?.(`[HomeKitCamera][${this.entityId}] HAP SetupEndpoints failed: ${
|
|
654
|
+
this.platform?.log?.warn?.(`[HomeKitCamera][${this.entityId}] HAP SetupEndpoints failed: ${sanitizeDiagnosticText(error)}`);
|
|
619
655
|
if (!callbackCompleted) {
|
|
620
656
|
callbackCompleted = true;
|
|
621
657
|
callback(error);
|
|
@@ -654,7 +690,18 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
654
690
|
callback(new Error(`Session ${request.sessionID} was not prepared`));
|
|
655
691
|
return;
|
|
656
692
|
}
|
|
657
|
-
|
|
693
|
+
let completed = false;
|
|
694
|
+
const done = (error) => {
|
|
695
|
+
if (completed)
|
|
696
|
+
return;
|
|
697
|
+
completed = true;
|
|
698
|
+
callback(error);
|
|
699
|
+
};
|
|
700
|
+
void this.startStream(session, request, done).catch((error) => {
|
|
701
|
+
if (this.activeSessions.get(request.sessionID) === session)
|
|
702
|
+
this.stopStream(request.sessionID);
|
|
703
|
+
done(new Error(sanitizeDiagnosticText(error instanceof Error ? error.message : String(error)) || "Camera session failed"));
|
|
704
|
+
});
|
|
658
705
|
return;
|
|
659
706
|
}
|
|
660
707
|
if (request.type === "reconfigure" /* StreamRequestTypes.RECONFIGURE */) {
|
|
@@ -679,143 +726,107 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
679
726
|
return url;
|
|
680
727
|
}
|
|
681
728
|
async startStream(session, request, callback) {
|
|
729
|
+
session.startup = new StreamStartupTiming();
|
|
730
|
+
session.startup.metrics.retries = 0;
|
|
682
731
|
const video = request.video;
|
|
683
|
-
const isC120 = this.isTapoC120();
|
|
684
732
|
const measuredFps = this.capabilities.measuredVideo?.fps;
|
|
685
733
|
const declaredFps = this.capabilities.maxFps ||
|
|
686
|
-
(measuredFps && measuredFps > 0 ? Math.round(measuredFps) :
|
|
734
|
+
(measuredFps && measuredFps > 0 ? Math.round(measuredFps) : 30);
|
|
687
735
|
const requestedFps = video?.fps;
|
|
688
736
|
const cameraMaxFps = this.capabilities.maxFps ||
|
|
689
|
-
(measuredFps && measuredFps > 0
|
|
737
|
+
(measuredFps && measuredFps > 0
|
|
738
|
+
? Math.max(15, Math.round(measuredFps))
|
|
739
|
+
: 30);
|
|
690
740
|
const effectiveFps = resolveLiveViewFps(requestedFps, measuredFps, this.capabilities.maxFps, cameraMaxFps);
|
|
691
741
|
const ffmpegPath = resolveFfmpegPath();
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
const
|
|
729
|
-
this.
|
|
730
|
-
|
|
731
|
-
(
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
url: freshTuyaUrl,
|
|
751
|
-
metadata: {
|
|
752
|
-
...this.streamSource.metadata,
|
|
753
|
-
sourceCameraEntityId: haEntityId,
|
|
754
|
-
isOmniTuyaDirect: true,
|
|
755
|
-
},
|
|
756
|
-
};
|
|
757
|
-
sourceUrl = this.getCleanSourceUrl();
|
|
758
|
-
renewedOmniSource = true;
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
catch {
|
|
762
|
-
// The signed Tuya URL must not enter Home Assistant or add-on logs.
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
if (wasOmniTuyaSource && !renewedOmniSource) {
|
|
766
|
-
// Never retry an expired signed URL. A failed renewal leaves HAP to
|
|
767
|
-
// report an unavailable source; the next HomeKit open will request again.
|
|
768
|
-
sourceUrl = "";
|
|
769
|
-
}
|
|
770
|
-
else if (!renewedOmniSource && state) {
|
|
771
|
-
try {
|
|
772
|
-
const fresh = await CameraSourceResolver.resolve(this.platform, haEntityId, state);
|
|
773
|
-
if (fresh && fresh.url) {
|
|
774
|
-
this.streamSource = {
|
|
775
|
-
...fresh,
|
|
776
|
-
metadata: {
|
|
777
|
-
...this.streamSource.metadata,
|
|
778
|
-
...fresh.metadata,
|
|
779
|
-
sourceCameraEntityId: fresh.metadata?.sourceCameraEntityId || haEntityId,
|
|
780
|
-
},
|
|
781
|
-
};
|
|
782
|
-
sourceUrl = this.getCleanSourceUrl();
|
|
783
|
-
}
|
|
742
|
+
const readerAdapter = new CameraSourceAdapter(this.platform, this.entityId, this.streamSource, this.capabilities, this.record);
|
|
743
|
+
if (readerAdapter.provider === "omni_tuya")
|
|
744
|
+
session.releaseReader = readerAdapter.acquireReader(session);
|
|
745
|
+
// Pause recording/motion readers BEFORE allocating an Omni session.
|
|
746
|
+
// Tuya allocation by a competing reader can invalidate the live URL.
|
|
747
|
+
this.emit("session-start", session.sessionId);
|
|
748
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
749
|
+
const allocationStarted = performance.now();
|
|
750
|
+
const adapter = new CameraSourceAdapter(this.platform, this.entityId, this.streamSource, this.capabilities, this.record);
|
|
751
|
+
let sourceUrl;
|
|
752
|
+
try {
|
|
753
|
+
this.streamSource = await adapter.resolveSession();
|
|
754
|
+
sourceUrl = this.getCleanSourceUrl();
|
|
755
|
+
}
|
|
756
|
+
catch {
|
|
757
|
+
sourceUrl = undefined;
|
|
758
|
+
}
|
|
759
|
+
if (this.activeSessions.get(session.sessionId) !== session) {
|
|
760
|
+
session.releaseReader?.();
|
|
761
|
+
callback(new Error("HAP session ended during source resolution"));
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
session.startup?.mark("T1");
|
|
765
|
+
if (session.startup)
|
|
766
|
+
session.startup.metrics.allocation1Ms =
|
|
767
|
+
performance.now() - allocationStarted;
|
|
768
|
+
if (!ffmpegPath || !sourceUrl) {
|
|
769
|
+
this.platform?.log?.warn?.(`[HomeKitCamera][${this.entityId}] HAP START rejected: ${!ffmpegPath ? "FFmpeg unavailable" : "stream source unavailable"}`);
|
|
770
|
+
callback(new Error("FFmpeg or RTSP source is unavailable"));
|
|
771
|
+
this.stopStream(session.sessionId);
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
// Omni issues a new single-session RTSP URL for each HomeKit open. The
|
|
775
|
+
// startup probe can therefore describe an older URL and incorrectly mark
|
|
776
|
+
// its audio as absent. Probe the exact URL about to be sent to FFmpeg.
|
|
777
|
+
if (this.streamSource.metadata?.isOmniTuyaDirect === true) {
|
|
778
|
+
const audioFormatKnown = this.capabilities.hasAudio &&
|
|
779
|
+
this.capabilities.audioCodec !== "none" &&
|
|
780
|
+
Number.isFinite(this.capabilities.audioSampleRate) &&
|
|
781
|
+
(this.capabilities.audioSampleRate || 0) > 0;
|
|
782
|
+
let probeConsumedReader = false;
|
|
783
|
+
if (!audioFormatKnown) {
|
|
784
|
+
const probeStarted = performance.now();
|
|
785
|
+
try {
|
|
786
|
+
const adapter = new CameraSourceAdapter(this.platform, this.entityId, this.streamSource, this.capabilities, this.record);
|
|
787
|
+
const { probe, performed } = await adapter.discover(sourceUrl);
|
|
788
|
+
probeConsumedReader = performed;
|
|
789
|
+
if (session.startup)
|
|
790
|
+
session.startup.metrics.probeMs = performance.now() - probeStarted;
|
|
791
|
+
if (probe.valid) {
|
|
792
|
+
this.capabilities.audioProvenance = "PROBED";
|
|
793
|
+
this.capabilities.hasAudio = probe.hasAudio;
|
|
794
|
+
this.capabilities.audioCodec = probe.hasAudio
|
|
795
|
+
? (probe.audioCodec || "incompatible")
|
|
796
|
+
: "none";
|
|
797
|
+
this.capabilities.audioSampleRate = probe.audioSampleRate;
|
|
798
|
+
this.capabilities.audioChannels = probe.audioChannels;
|
|
799
|
+
this.platform?.log?.notice?.(`[HomeKitCamera][${this.entityId}] Fresh Omni stream probe: audio=${probe.hasAudio ? `${probe.audioCodec || "present"}/${probe.audioSampleRate || "unknown"}Hz` : "absent"}`);
|
|
784
800
|
}
|
|
785
|
-
catch { }
|
|
786
801
|
}
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
this.platform.ha.requestCameraStream) {
|
|
791
|
-
try {
|
|
792
|
-
const freshUrl = await this.platform.ha.requestCameraStream(haEntityId);
|
|
793
|
-
if (freshUrl) {
|
|
794
|
-
this.streamSource.url = freshUrl;
|
|
795
|
-
this.streamSource.sourceType = "hls";
|
|
796
|
-
sourceUrl = this.getCleanSourceUrl();
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
catch { }
|
|
802
|
+
catch {
|
|
803
|
+
// The stream start remains available; the existing capability record
|
|
804
|
+
// decides whether Apple receives an audio RTP branch.
|
|
800
805
|
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
806
|
+
}
|
|
807
|
+
// Metadata probing is a separate RTSP reader. Allocate another signed
|
|
808
|
+
// URL for the actual live process instead of reopening the probe URL.
|
|
809
|
+
if (probeConsumedReader) {
|
|
810
|
+
const allocation2Started = performance.now();
|
|
811
|
+
const freshUrl = await this.platform?.ha?.requestOmniTuyaCameraStream?.(this.streamSource.metadata?.sourceCameraEntityId || this.entityId);
|
|
812
|
+
if (!freshUrl) {
|
|
813
|
+
callback(new Error("Omni could not renew the live stream after probing"));
|
|
814
|
+
this.stopStream(session.sessionId);
|
|
815
|
+
return;
|
|
811
816
|
}
|
|
817
|
+
this.streamSource.url = freshUrl;
|
|
818
|
+
sourceUrl = this.getCleanSourceUrl();
|
|
819
|
+
if (session.startup)
|
|
820
|
+
session.startup.metrics.allocation2Ms =
|
|
821
|
+
performance.now() - allocation2Started;
|
|
812
822
|
}
|
|
813
823
|
}
|
|
814
|
-
if (
|
|
815
|
-
|
|
816
|
-
callback(new Error("
|
|
824
|
+
if (this.activeSessions.get(session.sessionId) !== session) {
|
|
825
|
+
session.releaseReader?.();
|
|
826
|
+
callback(new Error("HAP session ended during source resolution"));
|
|
817
827
|
return;
|
|
818
828
|
}
|
|
829
|
+
session.startup?.mark("T2");
|
|
819
830
|
// HomeKit on iOS can request default low bitrates (e.g. 299k).
|
|
820
831
|
// Ensure a high-fidelity floor: at least 3500k-5000k for 2K (Tapo/Wyze), 6000k-8000k for 4K.
|
|
821
832
|
const qualityFloor = video.width >= 3840
|
|
@@ -840,7 +851,6 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
840
851
|
this.prepareTimeouts.delete(session.sessionId);
|
|
841
852
|
}
|
|
842
853
|
this.platform?.log?.notice?.(`[HomeKitCamera][${this.entityId}] [Session][${session.sessionId}] session-start ${video.width}x${video.height} | FPS[declarado=${declaredFps}, solicitado=${requestedFps ?? "omitted"}, medido=${measuredFps ?? "unmeasured"}, efectivo=${effectiveFps ?? "auto"}]`);
|
|
843
|
-
this.emit("session-start", session.sessionId);
|
|
844
854
|
// Yield event loop without artificial delay so background listeners handle pause immediately
|
|
845
855
|
await new Promise((resolve) => setImmediate(resolve));
|
|
846
856
|
let callbackSettled = false;
|
|
@@ -848,41 +858,62 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
848
858
|
if (callbackSettled)
|
|
849
859
|
return;
|
|
850
860
|
callbackSettled = true;
|
|
861
|
+
session.startup?.mark("T7");
|
|
851
862
|
callback(error);
|
|
852
863
|
};
|
|
864
|
+
if (this.activeSessions.get(session.sessionId) !== session) {
|
|
865
|
+
session.releaseReader?.();
|
|
866
|
+
settle(new Error("HAP session ended before media spawn"));
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
853
869
|
this.spawnFfmpegProcess(session, request, settle, false);
|
|
854
870
|
}
|
|
855
871
|
spawnFfmpegProcess(session, request, settle, forceTranscode = false) {
|
|
856
872
|
const ffmpegPath = resolveFfmpegPath() || "ffmpeg";
|
|
857
873
|
const sourceUrl = this.getCleanSourceUrl();
|
|
858
874
|
const video = request.video;
|
|
859
|
-
const isTapoC120 = this.isTapoC120();
|
|
860
875
|
const measuredFps = this.capabilities.measuredVideo?.fps;
|
|
861
876
|
const declaredFps = this.capabilities.maxFps ||
|
|
862
|
-
(measuredFps && measuredFps > 0 ? Math.round(measuredFps) :
|
|
877
|
+
(measuredFps && measuredFps > 0 ? Math.round(measuredFps) : 30);
|
|
863
878
|
const requestedFps = video?.fps;
|
|
864
879
|
const cameraMaxFps = this.capabilities.maxFps ||
|
|
865
|
-
(measuredFps && measuredFps > 0
|
|
880
|
+
(measuredFps && measuredFps > 0
|
|
881
|
+
? Math.max(15, Math.round(measuredFps))
|
|
882
|
+
: 30);
|
|
866
883
|
const effectiveFps = resolveLiveViewFps(requestedFps, measuredFps, this.capabilities.maxFps, cameraMaxFps);
|
|
867
884
|
const mtu = video.mtu || 1378;
|
|
868
885
|
const args = this.buildStreamArgs(session, request, forceTranscode);
|
|
869
|
-
|
|
870
|
-
const isTapoCamera = isTapoC402 || isTapoC120;
|
|
871
|
-
this.platform?.log?.notice?.(`[HomeKitCamera][${this.entityId}] HAP START ${video.width}x${video.height} forceTranscode=${forceTranscode} profile=${h264Profile(video.profile)} level=${h264Level(video.level)} mtu=${mtu} fps[declarado=${declaredFps}, solicitado=${requestedFps ?? "omitted"}, medido=${measuredFps ?? "unmeasured"}, efectivo=${effectiveFps ?? "auto"}] source=${sanitizeUrlCredentials(sourceUrl || "")} ffmpeg=${ffmpegPath} ${getFfmpegVersion(ffmpegPath) || "unknown"}`);
|
|
886
|
+
this.platform?.log?.notice?.(`[HomeKitCamera][${this.entityId}] HAP START ${video.width}x${video.height} forceTranscode=${forceTranscode} profile=${h264Profile(video.profile)} level=${h264Level(video.level)} mtu=${mtu} fps[declarado=${declaredFps}, solicitado=${requestedFps ?? "omitted"}, medido=${measuredFps ?? "unmeasured"}, efectivo=${effectiveFps ?? "auto"}] source=[camera-source] ffmpeg=${ffmpegPath} ${getFfmpegVersion(ffmpegPath) || "unknown"}`);
|
|
872
887
|
const isHaProxyStream = this.streamSource.sourceType === "ha_proxy" ||
|
|
873
888
|
this.streamSource.sourceType === "mjpeg" ||
|
|
874
889
|
Boolean(sourceUrl &&
|
|
875
890
|
(sourceUrl.includes("/api/camera_proxy_stream/") ||
|
|
876
891
|
sourceUrl.includes("/api/camera_proxy/")));
|
|
877
892
|
try {
|
|
893
|
+
const spawnStarted = performance.now();
|
|
878
894
|
const process = spawn(ffmpegPath, args, {
|
|
879
895
|
stdio: [
|
|
880
896
|
isHaProxyStream ? "pipe" : "ignore",
|
|
881
|
-
(isTapoC402 || isTapoC120) ? "pipe" : "ignore",
|
|
882
897
|
"pipe",
|
|
898
|
+
"pipe",
|
|
899
|
+
this.streamSource.metadata?.isOmniTuyaDirect === true &&
|
|
900
|
+
/^rtsps?:\/\//i.test(sourceUrl || "")
|
|
901
|
+
? "pipe"
|
|
902
|
+
: "ignore",
|
|
883
903
|
],
|
|
884
904
|
});
|
|
885
905
|
session.process = process;
|
|
906
|
+
process.once("spawn", () => {
|
|
907
|
+
if (session.startup)
|
|
908
|
+
session.startup.metrics.ffmpegSpawnMs =
|
|
909
|
+
performance.now() - spawnStarted;
|
|
910
|
+
});
|
|
911
|
+
const recordingPipe = process.stdio[3];
|
|
912
|
+
if (recordingPipe && typeof recordingPipe !== "string") {
|
|
913
|
+
recordingPipe.on("data", (chunk) => {
|
|
914
|
+
this.emit("recording-analysis-data", chunk);
|
|
915
|
+
});
|
|
916
|
+
}
|
|
886
917
|
if (isHaProxyStream && sourceUrl) {
|
|
887
918
|
this.startHaCameraProxyPipe(session, process, sourceUrl);
|
|
888
919
|
}
|
|
@@ -894,24 +925,16 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
894
925
|
for (const line of chunk.toString().split(/\r?\n/)) {
|
|
895
926
|
this.recordFfmpegProgress(session, line);
|
|
896
927
|
}
|
|
897
|
-
if ((!isTapoC402 && !isTapoC120) || startupConfirmed)
|
|
898
|
-
return;
|
|
899
|
-
progress = `${progress}${chunk.toString()}`.slice(-2048);
|
|
900
|
-
for (const match of progress.matchAll(/(?:^|\n)frame=\s*(\d+)/g)) {
|
|
901
|
-
if (Number(match[1]) > 0) {
|
|
902
|
-
startupConfirmed = true;
|
|
903
|
-
if (startupTimer)
|
|
904
|
-
clearTimeout(startupTimer);
|
|
905
|
-
this.platform?.log?.notice?.(`[HomeKitCamera][${this.entityId}] ${isTapoC402 ? "C402" : "C120"} HAP startup confirmed by first video frame`);
|
|
906
|
-
settle();
|
|
907
|
-
break;
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
928
|
});
|
|
911
929
|
process.stderr?.on("data", (chunk) => {
|
|
912
930
|
const text = chunk.toString();
|
|
931
|
+
if (/Input #|Stream #0/.test(text))
|
|
932
|
+
session.startup?.mark("T3");
|
|
913
933
|
for (const line of text.split(/\r?\n/)) {
|
|
914
934
|
this.recordFfmpegProgress(session, line);
|
|
935
|
+
if (/pblack:\d+/.test(line)) {
|
|
936
|
+
this.emit("motion-analysis-line", line);
|
|
937
|
+
}
|
|
915
938
|
}
|
|
916
939
|
// Keep a short, pre-sanitized failure summary only. Raw FFmpeg stderr
|
|
917
940
|
// can contain source URLs or HTTP authorization headers.
|
|
@@ -920,23 +943,11 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
920
943
|
stderr = `${stderr}\n${safe}`.slice(-1200);
|
|
921
944
|
});
|
|
922
945
|
const guard = setTimeout(() => {
|
|
923
|
-
if (
|
|
924
|
-
this.platform?.log?.notice?.(`[HomeKitCamera][${this.entityId}] HAP START callback success; FFmpeg active session=${session.sessionId}`);
|
|
946
|
+
if (process.exitCode === null && !process.killed)
|
|
925
947
|
settle();
|
|
926
|
-
|
|
927
|
-
else if (!isTapoC402 && !isTapoC120) {
|
|
948
|
+
else
|
|
928
949
|
settle(new Error("FFmpeg exited during HAP startup"));
|
|
929
|
-
}
|
|
930
950
|
}, 400);
|
|
931
|
-
if (isTapoC402 || isTapoC120) {
|
|
932
|
-
clearTimeout(guard);
|
|
933
|
-
startupTimer = setTimeout(() => {
|
|
934
|
-
if (startupConfirmed)
|
|
935
|
-
return;
|
|
936
|
-
this.platform?.log?.warn?.(`[HomeKitCamera][${this.entityId}] ${isTapoC402 ? "C402" : "C120"} timeout waiting for first video frame (6s); settling callback`);
|
|
937
|
-
settle();
|
|
938
|
-
}, 6000);
|
|
939
|
-
}
|
|
940
951
|
process.once("error", (error) => {
|
|
941
952
|
clearTimeout(guard);
|
|
942
953
|
if (startupTimer)
|
|
@@ -944,10 +955,15 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
944
955
|
settle(error);
|
|
945
956
|
});
|
|
946
957
|
process.once("close", (code) => {
|
|
958
|
+
if (this.activeSessions.get(session.sessionId) !== session ||
|
|
959
|
+
session.process !== process)
|
|
960
|
+
return;
|
|
947
961
|
clearTimeout(guard);
|
|
948
962
|
if (startupTimer)
|
|
949
963
|
clearTimeout(startupTimer);
|
|
950
964
|
session.process = undefined;
|
|
965
|
+
if (code !== 0)
|
|
966
|
+
new CameraSourceAdapter(this.platform, this.entityId, this.streamSource, this.capabilities, this.record).invalidate();
|
|
951
967
|
this.platform?.log?.warn?.(`[HomeKitCamera][${this.entityId}] FFmpeg closed code=${code} ${stderr.trim()}`);
|
|
952
968
|
// Automatic fallback recovery: if initial attempt failed (e.g. missing audio track or incompatible passthrough),
|
|
953
969
|
// retry immediately with safe transcoding and/or silent audio fallback
|
|
@@ -955,7 +971,43 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
955
971
|
!session.retried &&
|
|
956
972
|
this.activeSessions.has(session.sessionId)) {
|
|
957
973
|
session.retried = true;
|
|
974
|
+
if (session.startup)
|
|
975
|
+
session.startup.metrics.retries =
|
|
976
|
+
(session.startup.metrics.retries || 0) + 1;
|
|
958
977
|
this.finishTelemetry(session, "failed", stderr || `FFmpeg exited with code ${code}`);
|
|
978
|
+
const isOmniStreamNotFound = this.streamSource.metadata?.isOmniTuyaDirect === true &&
|
|
979
|
+
/(?:DESCRIBE failed:\s*404|404\s+Stream Not Found)/i.test(stderr);
|
|
980
|
+
if (isOmniStreamNotFound) {
|
|
981
|
+
const sourceEntityId = this.streamSource.metadata?.sourceCameraEntityId || this.entityId;
|
|
982
|
+
void (async () => {
|
|
983
|
+
const state = this.platform?.ha?.hassStates?.get(sourceEntityId);
|
|
984
|
+
const fallback = await CameraSourceResolver.resolveOmniTuyaFallback(this.platform, sourceEntityId, state, { allowCameraProxy: false });
|
|
985
|
+
if (fallback?.url) {
|
|
986
|
+
this.streamSource = fallback;
|
|
987
|
+
this.platform?.log?.warn?.(`[HomeKitCamera][${this.entityId}] Omni RTSP returned 404 Stream Not Found; retrying Live View through Home Assistant's stream/proxy route.`);
|
|
988
|
+
this.spawnFfmpegProcess(session, request, settle, false);
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
this.platform?.log?.error?.(`[HomeKitCamera][${this.entityId}] Omni RTSP returned 404 and Home Assistant could not provide a fallback stream.`);
|
|
992
|
+
settle(new Error("Omni RTSP stream not found; HA fallback unavailable"));
|
|
993
|
+
session.videoRelay?.close();
|
|
994
|
+
session.audioRelay?.close();
|
|
995
|
+
session.releaseReader?.();
|
|
996
|
+
this.activeSessions.delete(session.sessionId);
|
|
997
|
+
if (this.activeSessions.size === 0)
|
|
998
|
+
this.emit("session-end");
|
|
999
|
+
})().catch((error) => {
|
|
1000
|
+
this.platform?.log?.warn?.(`[HomeKitCamera][${this.entityId}] Could not switch Omni Live View to Home Assistant fallback: ${sanitizeDiagnosticText(error instanceof Error ? error.message : "unknown error")}`);
|
|
1001
|
+
settle(new Error("Omni RTSP fallback failed"));
|
|
1002
|
+
session.videoRelay?.close();
|
|
1003
|
+
session.audioRelay?.close();
|
|
1004
|
+
session.releaseReader?.();
|
|
1005
|
+
this.activeSessions.delete(session.sessionId);
|
|
1006
|
+
if (this.activeSessions.size === 0)
|
|
1007
|
+
this.emit("session-end");
|
|
1008
|
+
});
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
959
1011
|
const is401 = stderr.includes("401") ||
|
|
960
1012
|
stderr.includes("Unauthorized") ||
|
|
961
1013
|
stderr.includes("Authentication failed");
|
|
@@ -980,6 +1032,9 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
980
1032
|
// Clean up the ghost session entry so the next HomeKit reconnect
|
|
981
1033
|
// finds a clean Map — otherwise stopStream() later can't properly
|
|
982
1034
|
// emit session-end and activeSessions grows with stale entries.
|
|
1035
|
+
session.videoRelay?.close();
|
|
1036
|
+
session.audioRelay?.close();
|
|
1037
|
+
session.releaseReader?.();
|
|
983
1038
|
this.activeSessions.delete(session.sessionId);
|
|
984
1039
|
if (this.activeSessions.size === 0) {
|
|
985
1040
|
this.emit("session-end");
|
|
@@ -991,33 +1046,33 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
991
1046
|
}
|
|
992
1047
|
}
|
|
993
1048
|
buildStreamArgs(session, request, forceTranscode = false) {
|
|
1049
|
+
if (["hevc", "h265"].includes(this.capabilities.videoCodec))
|
|
1050
|
+
throw new Error("HEVC requires SecureVideoController");
|
|
994
1051
|
const sourceUrl = this.getCleanSourceUrl();
|
|
995
1052
|
if (!sourceUrl) {
|
|
996
1053
|
return [];
|
|
997
1054
|
}
|
|
998
1055
|
const video = request.video;
|
|
999
|
-
const isTapoC120 = this.isTapoC120();
|
|
1000
1056
|
const measuredFps = this.capabilities.measuredVideo?.fps;
|
|
1001
1057
|
const declaredFps = this.capabilities.maxFps ||
|
|
1002
|
-
(measuredFps && measuredFps > 0 ? Math.round(measuredFps) :
|
|
1058
|
+
(measuredFps && measuredFps > 0 ? Math.round(measuredFps) : 30);
|
|
1003
1059
|
const requestedFps = video.fps;
|
|
1004
1060
|
const cameraMaxFps = this.capabilities.maxFps ||
|
|
1005
|
-
(measuredFps && measuredFps > 0
|
|
1061
|
+
(measuredFps && measuredFps > 0
|
|
1062
|
+
? Math.max(15, Math.round(measuredFps))
|
|
1063
|
+
: 30);
|
|
1006
1064
|
const resolvedFps = resolveLiveViewFps(requestedFps, measuredFps, this.capabilities.maxFps, cameraMaxFps);
|
|
1007
1065
|
const mtu = video.mtu || 1378;
|
|
1008
1066
|
const host = formatHost(session.targetAddress);
|
|
1009
|
-
const videoUrl =
|
|
1010
|
-
|
|
1067
|
+
const videoUrl = session.videoRelay
|
|
1068
|
+
? `srtp://127.0.0.1:${session.videoRelay.inputPort}?rtcpport=${session.videoRelay.inputPort}&pkt_size=${mtu}`
|
|
1069
|
+
: `srtp://${host}:${session.videoPort}` +
|
|
1070
|
+
`?rtcpport=${session.videoPort}&localrtcpport=${session.localVideoPort}&pkt_size=${mtu}&buffer_size=1048576${session.localAddress ? `&localaddr=${encodeURIComponent(session.localAddress)}` : ""}`;
|
|
1011
1071
|
const isHaProxyStream = this.streamSource.sourceType === "ha_proxy" ||
|
|
1012
1072
|
this.streamSource.sourceType === "mjpeg" ||
|
|
1013
1073
|
Boolean(sourceUrl &&
|
|
1014
1074
|
(sourceUrl.includes("/api/camera_proxy_stream/") ||
|
|
1015
1075
|
sourceUrl.includes("/api/camera_proxy/")));
|
|
1016
|
-
// Camera.UI/go2rtc can accept RTSP before its next keyframe is available.
|
|
1017
|
-
// A 32 KiB / zero-duration probe then exits with "non-existing PPS" after
|
|
1018
|
-
// HAP has already accepted the Live View request. C402 needs a complete
|
|
1019
|
-
// GOP to join reliably; video remains strict H.264 passthrough.
|
|
1020
|
-
const isTapoC402 = this.isTapoC402();
|
|
1021
1076
|
const args = [
|
|
1022
1077
|
"-hide_banner",
|
|
1023
1078
|
"-loglevel",
|
|
@@ -1027,13 +1082,7 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
1027
1082
|
"-protocol_whitelist",
|
|
1028
1083
|
"pipe,udp,rtp,file,crypto,srtp,tcp,tls,http,https,lavfi,rtsp,rtsps",
|
|
1029
1084
|
];
|
|
1030
|
-
|
|
1031
|
-
args.push("-progress", "pipe:1", "-stats_period", "0.25");
|
|
1032
|
-
}
|
|
1033
|
-
else {
|
|
1034
|
-
// Progress is diagnostics only. It does not alter RTP/SRTP, codecs, or media flow.
|
|
1035
|
-
args.push("-progress", "pipe:2", "-stats_period", "0.5");
|
|
1036
|
-
}
|
|
1085
|
+
args.push("-progress", "pipe:1", "-stats_period", "0.25");
|
|
1037
1086
|
if (isHaProxyStream) {
|
|
1038
1087
|
// Home Assistant's continuous camera proxy emits multipart JPEG frames.
|
|
1039
1088
|
// The old PNG decoder rejected those frames, so HAP published but never
|
|
@@ -1042,23 +1091,7 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
1042
1091
|
}
|
|
1043
1092
|
else if (sourceUrl.startsWith("rtsp://") ||
|
|
1044
1093
|
sourceUrl.startsWith("rtsps://")) {
|
|
1045
|
-
args.push("-rtsp_transport", "tcp", "-timeout", "10000000",
|
|
1046
|
-
// C402 needs 2MB for its long GOP analysis.
|
|
1047
|
-
// C120 at 1080p passthrough uses 128KB and 200ms for instant start.
|
|
1048
|
-
// EZVIZ 1080p uses 128KB and 200ms analyze duration for instant startup without waiting.
|
|
1049
|
-
// Wyze and other network RTSP cameras use 64KB-128KB for fast startup.
|
|
1050
|
-
"-probesize", isTapoC402 ? "2097152" : (isTapoC120 || this.isEzviz()) ? "131072" : "65536", "-analyzeduration", isTapoC402 ? "3000000" : (isTapoC120 || this.isEzviz()) ? "200000" : "100000");
|
|
1051
|
-
if (isTapoC402) {
|
|
1052
|
-
args.push("-fflags", "+genpts+discardcorrupt", "-flags", "low_delay");
|
|
1053
|
-
}
|
|
1054
|
-
else if (isTapoC120) {
|
|
1055
|
-
// C120: Wallclock timestamping to eliminate RTP jitter buffer drops and 3-10s jumping
|
|
1056
|
-
args.push("-use_wallclock_as_timestamps", "1", "-fflags", "+nobuffer+flush_packets+genpts+discardcorrupt", "-flags", "low_delay");
|
|
1057
|
-
}
|
|
1058
|
-
else {
|
|
1059
|
-
args.push("-fflags", "+nobuffer+flush_packets+genpts+discardcorrupt", "-flags", "low_delay");
|
|
1060
|
-
}
|
|
1061
|
-
args.push("-thread_queue_size", isTapoC120 ? "1024" : "512", "-i", sourceUrl);
|
|
1094
|
+
args.push("-rtsp_transport", "tcp", "-timeout", "10000000", "-probesize", "2097152", "-analyzeduration", "3000000", "-fflags", "+genpts+discardcorrupt", "-flags", "low_delay", "-thread_queue_size", "512", "-i", sourceUrl);
|
|
1062
1095
|
}
|
|
1063
1096
|
else if (sourceUrl.startsWith("http://") ||
|
|
1064
1097
|
sourceUrl.startsWith("https://")) {
|
|
@@ -1066,43 +1099,20 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
1066
1099
|
if (sourceUrl.startsWith("https://")) {
|
|
1067
1100
|
args.push("-tls_verify", "0");
|
|
1068
1101
|
}
|
|
1069
|
-
|
|
1070
|
-
const sToken = String(this.streamSource.metadata.scryptedToken).trim();
|
|
1071
|
-
if (sToken) {
|
|
1072
|
-
args.push("-headers", `Authorization: ${sToken.startsWith("Bearer ") ? sToken : `Bearer ${sToken}`}\r\n`);
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
else if (this.entityId.startsWith("camera.") ||
|
|
1076
|
-
this.streamSource.metadata?.sourceCameraEntityId ||
|
|
1077
|
-
this.streamSource.metadata?.isDirectHa) {
|
|
1078
|
-
// HA's camera/stream URLs are protected by the HA API token. Refreshing
|
|
1079
|
-
// the URL per HomeKit session is insufficient if FFmpeg omits auth.
|
|
1080
|
-
const token = this.platform?.ha?.getAccessToken?.() ||
|
|
1081
|
-
this.platform?.ha?.wsAccessToken;
|
|
1082
|
-
if (token) {
|
|
1083
|
-
args.push("-headers", `Authorization: Bearer ${token}\r\n`);
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1102
|
+
args.push(...new CameraSourceAdapter(this.platform, this.entityId, this.streamSource, this.capabilities, this.record).inputArguments());
|
|
1086
1103
|
args.push("-i", sourceUrl);
|
|
1087
1104
|
}
|
|
1088
1105
|
else {
|
|
1089
1106
|
args.push("-i", sourceUrl);
|
|
1090
1107
|
}
|
|
1108
|
+
const audioPlan = h264AudioPlan(this.capabilities);
|
|
1091
1109
|
const hasAudioRequested = Boolean(request.audio &&
|
|
1092
1110
|
session.audioPort &&
|
|
1093
1111
|
session.localAudioPort &&
|
|
1094
1112
|
session.audioSsrc &&
|
|
1095
|
-
session.audioKeySalt
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
this.capabilities.hasAudio === false ||
|
|
1099
|
-
this.capabilities.audioCodec === "none");
|
|
1100
|
-
const sampleRate = request.audio?.sample_rate === 24 /* AudioStreamingSamplerate.KHZ_24 */
|
|
1101
|
-
? 24000
|
|
1102
|
-
: 16000;
|
|
1103
|
-
if (needsSilentAudio) {
|
|
1104
|
-
args.push("-re", "-f", "lavfi", "-i", `anullsrc=channel_layout=mono:sample_rate=${sampleRate}`);
|
|
1105
|
-
}
|
|
1113
|
+
session.audioKeySalt &&
|
|
1114
|
+
audioPlan.codec !== "unavailable");
|
|
1115
|
+
const sampleRate = audioPlan.codec === "unavailable" ? 24000 : audioPlan.sampleRate;
|
|
1106
1116
|
const codec = (this.capabilities.videoCodec || "h264").toLowerCase();
|
|
1107
1117
|
// HAP's RTP VideoStream service advertises H.264 profiles only. Copying
|
|
1108
1118
|
// HEVC into that RTP session makes FFmpeg appear healthy while Apple Home
|
|
@@ -1110,7 +1120,14 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
1110
1120
|
// remains native up to this output boundary, then is converted solely for
|
|
1111
1121
|
// Both Tapo C402 and C120 are native 1080p H.264 streams; they use pure copy passthrough
|
|
1112
1122
|
// (-c:v copy) with zero software transcoding and zero CPU load.
|
|
1113
|
-
const
|
|
1123
|
+
const h264Plan = this.capabilities.videoCodec === "h264"
|
|
1124
|
+
? h264VideoPlan(this.capabilities, this.capabilities.resolution.width > 1920 ||
|
|
1125
|
+
this.capabilities.resolution.height > 1080 ||
|
|
1126
|
+
forceTranscode
|
|
1127
|
+
? verifiedH264Encoder()
|
|
1128
|
+
: undefined, forceTranscode)
|
|
1129
|
+
: undefined;
|
|
1130
|
+
const needsTapoVideoNormalization = h264Plan?.mode === "normalization";
|
|
1114
1131
|
const isHevc = codec === "hevc" ||
|
|
1115
1132
|
codec === "h265" ||
|
|
1116
1133
|
this.capabilities.strategy === "passthrough_hevc";
|
|
@@ -1134,13 +1151,7 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
1134
1151
|
: undefined);
|
|
1135
1152
|
// Pure passthrough remuxing without transcoding CPU overhead (native 4K, 2K, 1080p, 720p @ max fps)
|
|
1136
1153
|
// Preserve the native H.264 or HEVC stream negotiated by Apple Home.
|
|
1137
|
-
const videoPassArgs = [
|
|
1138
|
-
"-map",
|
|
1139
|
-
"0:v:0",
|
|
1140
|
-
"-an",
|
|
1141
|
-
"-c:v",
|
|
1142
|
-
"copy",
|
|
1143
|
-
];
|
|
1154
|
+
const videoPassArgs = ["-map", "0:v:0", "-an", "-c:v", "copy"];
|
|
1144
1155
|
// Only apply H.264 bitstream filter to H.264 streams; HEVC streams do not use dump_extra
|
|
1145
1156
|
if (!isHevc) {
|
|
1146
1157
|
videoPassArgs.push("-bsf:v", "dump_extra=freq=keyframe");
|
|
@@ -1148,46 +1159,33 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
1148
1159
|
videoPassArgs.push("-f", "rtp", "-fflags", "+nobuffer+flush_packets", "-max_delay", "0", "-max_interleave_delta", "100000", "-payload_type", String(video.pt || 99), "-ssrc", String(session.videoSsrc), "-srtp_out_suite", suiteName(session.videoCryptoSuite), "-srtp_out_params", session.videoKeySalt.toString("base64"), videoUrl);
|
|
1149
1160
|
args.push(...videoPassArgs);
|
|
1150
1161
|
}
|
|
1151
|
-
else if (needsTapoVideoNormalization
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
// pairing recovers before it receives the refreshed capabilities.
|
|
1155
|
-
const targetWidth = Math.min(1920, Math.max(2, Math.floor((video.width || 1920) / 2) * 2));
|
|
1156
|
-
const targetHeight = Math.min(1080, Math.max(2, Math.floor((video.height || 1080) / 2) * 2));
|
|
1157
|
-
const tapoFps = Math.min(resolvedFps ?? 15, isTapoC120 ? 20 : 15);
|
|
1158
|
-
const keyframeInterval = Math.max(15, tapoFps * 2);
|
|
1159
|
-
this.startTelemetry(session, request, session.retried ? "fallback" : "normalization", {
|
|
1162
|
+
else if (needsTapoVideoNormalization &&
|
|
1163
|
+
h264Plan?.mode === "normalization") {
|
|
1164
|
+
this.startTelemetry(session, request, "normalization", {
|
|
1160
1165
|
codec: "h264",
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
height: targetHeight,
|
|
1165
|
-
declaredFps,
|
|
1166
|
-
requestedFps,
|
|
1167
|
-
measuredFps,
|
|
1168
|
-
effectiveFps: tapoFps,
|
|
1169
|
-
configuredFps: tapoFps,
|
|
1170
|
-
bitrateKbps: 4500,
|
|
1166
|
+
width: h264Plan.width,
|
|
1167
|
+
height: h264Plan.height,
|
|
1168
|
+
fps: resolvedFps,
|
|
1171
1169
|
pixFmt: "yuv420p",
|
|
1172
1170
|
metadataSource: "effective-command",
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
: undefined);
|
|
1178
|
-
this.platform?.log?.notice?.(`[Stream][${this.entityId}] Normalizando Tapo ${isTapoC402 ? "C402" : "C120"} H.264 a HAP High L4.0 ${targetWidth}x${targetHeight}@${tapoFps} (declarado=${declaredFps}, solicitado=${requestedFps ?? "omitted"}, medido=${measuredFps ?? "unmeasured"}, efectivo=${tapoFps})`);
|
|
1179
|
-
args.push("-map", "0:v:0", "-an", "-vf", `scale=${targetWidth}:${targetHeight}:flags=fast_bilinear`, "-c:v", "libx264", "-preset", "veryfast", "-tune", "zerolatency", "-profile:v", "high", "-level:v", "4.0", "-pix_fmt", "yuv420p", "-r", String(tapoFps), "-g", String(keyframeInterval), "-keyint_min", String(tapoFps), "-sc_threshold", "0", "-b:v", "4500k", "-maxrate", "5000k", "-bufsize", "5000k", "-f", "rtp", "-fflags", "+nobuffer+flush_packets", "-max_delay", "0", "-payload_type", String(video.pt || 99), "-ssrc", String(session.videoSsrc), "-srtp_out_suite", suiteName(session.videoCryptoSuite), "-srtp_out_params", session.videoKeySalt.toString("base64"), videoUrl);
|
|
1171
|
+
});
|
|
1172
|
+
args.push("-map", "0:v:0", "-an", "-vf", `scale=${h264Plan.width}:${h264Plan.height}:flags=fast_bilinear`, "-c:v", h264Plan.encoder, "-pix_fmt", "yuv420p", "-profile:v", "high", "-level:v", "4.0", ...(h264Plan.encoder === "libx264"
|
|
1173
|
+
? ["-preset", "veryfast", "-tune", "zerolatency"]
|
|
1174
|
+
: ["-realtime", "1"]), "-f", "rtp", "-payload_type", String(video.pt || 99), "-ssrc", String(session.videoSsrc), "-srtp_out_suite", suiteName(session.videoCryptoSuite), "-srtp_out_params", session.videoKeySalt.toString("base64"), videoUrl);
|
|
1180
1175
|
}
|
|
1181
1176
|
else {
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
const
|
|
1186
|
-
const
|
|
1177
|
+
const encoder = verifiedH264Encoder();
|
|
1178
|
+
if (!encoder)
|
|
1179
|
+
throw new Error("No verified H264 encoder for source normalization");
|
|
1180
|
+
const sourceWidth = this.capabilities.resolution?.width || video.width || 1920;
|
|
1181
|
+
const sourceHeight = this.capabilities.resolution?.height || video.height || 1080;
|
|
1182
|
+
const scale = Math.min(1, 1920 / sourceWidth, 1080 / sourceHeight);
|
|
1183
|
+
const targetWidth = Math.max(2, Math.floor((sourceWidth * scale) / 2) * 2);
|
|
1184
|
+
const targetHeight = Math.max(2, Math.floor((sourceHeight * scale) / 2) * 2);
|
|
1187
1185
|
const hevcFps = resolvedFps ?? this.capabilities.maxFps ?? 20;
|
|
1188
1186
|
const keyframeInterval = Math.max(15, hevcFps * 2);
|
|
1189
1187
|
const targetBitrate = targetWidth >= 2560 ? 4500 : targetWidth >= 1920 ? 3500 : 2000;
|
|
1190
|
-
this.platform?.log?.notice?.(`[Stream][${this.entityId}]
|
|
1188
|
+
this.platform?.log?.notice?.(`[Stream][${this.entityId}] Source normalization to H.264 ${targetWidth}x${targetHeight}@${hevcFps}fps bitrate=${targetBitrate}k (source codec: ${this.capabilities.videoCodec || "unknown"})`);
|
|
1191
1189
|
this.startTelemetry(session, request, session.retried ? "fallback" : "transcode", {
|
|
1192
1190
|
codec: "h264",
|
|
1193
1191
|
profile: "high",
|
|
@@ -1202,17 +1200,28 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
1202
1200
|
bitrateKbps: targetBitrate,
|
|
1203
1201
|
pixFmt: "yuv420p",
|
|
1204
1202
|
metadataSource: "effective-command",
|
|
1205
|
-
}, session.retried
|
|
1206
|
-
|
|
1203
|
+
}, session.retried
|
|
1204
|
+
? "FFmpeg restarted after an initial stream failure"
|
|
1205
|
+
: undefined);
|
|
1206
|
+
args.push("-map", "0:v:0", "-an", "-vf", `scale=${targetWidth}:${targetHeight}:flags=fast_bilinear`, "-c:v", encoder, ...(encoder === "libx264"
|
|
1207
|
+
? ["-preset", "veryfast", "-tune", "zerolatency"]
|
|
1208
|
+
: ["-realtime", "1"]), "-profile:v", "high", "-level:v", "4.0", "-pix_fmt", "yuv420p", "-r", String(hevcFps), "-g", String(keyframeInterval), "-keyint_min", String(hevcFps), ...(encoder === "libx264" ? ["-sc_threshold", "0"] : []), "-b:v", `${targetBitrate}k`, "-maxrate", `${targetBitrate + 500}k`, "-bufsize", `${targetBitrate + 500}k`, "-f", "rtp", "-fflags", "+nobuffer+flush_packets", "-max_delay", "0", "-payload_type", String(video.pt || 99), "-ssrc", String(session.videoSsrc), "-srtp_out_suite", suiteName(session.videoCryptoSuite), "-srtp_out_params", session.videoKeySalt.toString("base64"), videoUrl);
|
|
1207
1209
|
}
|
|
1208
1210
|
if (hasAudioRequested &&
|
|
1209
1211
|
session.audioKeySalt &&
|
|
1210
1212
|
session.audioSsrc &&
|
|
1211
1213
|
request.audio) {
|
|
1212
|
-
const localAudioPort = session.localAudioPort ||
|
|
1213
|
-
const audioUrl =
|
|
1214
|
-
|
|
1215
|
-
|
|
1214
|
+
const localAudioPort = session.localAudioPort || session.localVideoPort + 1;
|
|
1215
|
+
const audioUrl = session.audioRelay
|
|
1216
|
+
? `srtp://127.0.0.1:${session.audioRelay.inputPort}?rtcpport=${session.audioRelay.inputPort}&pkt_size=188`
|
|
1217
|
+
: `srtp://${host}:${session.audioPort}` +
|
|
1218
|
+
`?rtcpport=${session.audioPort}&localrtcpport=${localAudioPort}&pkt_size=188`;
|
|
1219
|
+
const isOpus = audioPlan.codec === "opus" &&
|
|
1220
|
+
request.audio.codec === "OPUS" /* AudioStreamingCodecType.OPUS */;
|
|
1221
|
+
if (request.audio.codec === "OPUS" /* AudioStreamingCodecType.OPUS */ && !isOpus)
|
|
1222
|
+
throw new Error("Opus requires a validated native Opus source");
|
|
1223
|
+
if (audioPlan.codec === "opus" && !isOpus)
|
|
1224
|
+
throw new Error("Audio codec was not advertised for this native Opus source");
|
|
1216
1225
|
const targetCodec = isOpus ? "opus" : "aac_eld";
|
|
1217
1226
|
// Apple HomeKit RTP Live View expects AAC-ELD (or Opus) audio packets.
|
|
1218
1227
|
// RTSP cameras provide AAC-LC, PCMA, or PCMU, which must be transcoded to AAC-ELD/AAC mono
|
|
@@ -1223,34 +1232,51 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
1223
1232
|
expectedChannels: 1,
|
|
1224
1233
|
};
|
|
1225
1234
|
const audioCompat = checkAudioPassthroughCompatibility(this.capabilities.audioCodec, this.capabilities.audioSampleRate, this.capabilities.audioChannels, targetReq);
|
|
1226
|
-
if (audioCompat.compatible) {
|
|
1227
|
-
this.platform?.log?.notice?.(`[Stream][${this.entityId}] Audio fuente es
|
|
1235
|
+
if (isOpus && audioCompat.compatible) {
|
|
1236
|
+
this.platform?.log?.notice?.(`[Stream][${this.entityId}] Audio fuente es Opus nativo compatible: transmitiendo con passthrough (-c:a copy)`);
|
|
1228
1237
|
args.push("-map", "0:a:0?", "-vn", "-c:a", "copy", "-f", "rtp", "-fflags", "+nobuffer+flush_packets", "-max_delay", "0", "-payload_type", String(request.audio.pt || 110), "-ssrc", String(session.audioSsrc), "-srtp_out_suite", suiteName(session.audioCryptoSuite || session.videoCryptoSuite), "-srtp_out_params", session.audioKeySalt.toString("base64"), audioUrl);
|
|
1229
1238
|
}
|
|
1230
|
-
else if (isOpus
|
|
1231
|
-
this.platform?.log?.notice?.(`[Stream][${this.entityId}] Transcodificando exclusivamente audio fuente (${this.capabilities.audioCodec || "desconocido"}) a
|
|
1239
|
+
else if (!isOpus && supportsFdkAac()) {
|
|
1240
|
+
this.platform?.log?.notice?.(`[Stream][${this.entityId}] Transcodificando exclusivamente audio fuente (${this.capabilities.audioCodec || "desconocido"}) a AAC-ELD para Apple Home`);
|
|
1232
1241
|
const audioBitrate = Math.min(request.audio.max_bit_rate || 24, 24);
|
|
1233
|
-
|
|
1234
|
-
args.push("-map", "1:a:0", "-vn");
|
|
1235
|
-
}
|
|
1236
|
-
else {
|
|
1237
|
-
args.push("-map", "0:a:0?", "-vn");
|
|
1238
|
-
}
|
|
1239
|
-
if (isOpus) {
|
|
1240
|
-
args.push("-c:a", "libopus", "-application", "lowdelay", "-frame_duration", "20", "-packet_loss", "5");
|
|
1241
|
-
}
|
|
1242
|
-
else {
|
|
1243
|
-
args.push("-c:a", "libfdk_aac", "-profile:a", "aac_eld", "-flags", "+global_header");
|
|
1244
|
-
}
|
|
1242
|
+
args.push("-map", "0:a:0?", "-vn", "-c:a", "libfdk_aac", "-profile:a", "aac_eld", "-frame_length", "480", "-flags", "+global_header");
|
|
1245
1243
|
args.push("-af", "aresample=async=1:first_pts=0", "-ar", String(sampleRate), "-ac", "1", "-b:a", `${audioBitrate}k`, "-f", "rtp", "-fflags", "+nobuffer+flush_packets", "-max_delay", "0", "-max_interleave_delta", "100000", "-payload_type", String(request.audio.pt || 110), "-ssrc", String(session.audioSsrc), "-srtp_out_suite", suiteName(session.audioCryptoSuite || session.videoCryptoSuite), "-srtp_out_params", session.audioKeySalt.toString("base64"), audioUrl);
|
|
1246
1244
|
}
|
|
1247
1245
|
else {
|
|
1248
1246
|
// Never send AAC-LC to a HomeKit session that negotiated AAC-ELD.
|
|
1249
|
-
//
|
|
1250
|
-
// this guard also protects an older pairing with cached capabilities.
|
|
1247
|
+
// Audio remains unavailable when the negotiated codec cannot be produced.
|
|
1251
1248
|
this.platform?.log?.warn?.(`[Stream][${this.entityId}] Omitiendo audio AAC-ELD: FFmpeg no incluye libfdk_aac; se conserva el video para HomeKit`);
|
|
1252
1249
|
}
|
|
1253
1250
|
}
|
|
1251
|
+
// Omni Tuya feeders allow one signed RTSP reader. Reuse this live FFmpeg
|
|
1252
|
+
// input for low-rate frame-difference motion analysis while Casa is open.
|
|
1253
|
+
// The detector's separate RTSP reader is paused during Live View.
|
|
1254
|
+
if (this.streamSource.metadata?.isOmniTuyaDirect === true &&
|
|
1255
|
+
/^rtsps?:\/\//i.test(sourceUrl)) {
|
|
1256
|
+
args.push("-map", "0:v:0", "-vf", "fps=1,scale=160:90,format=gray,tblend=all_mode=difference,blackframe=amount=0:thresh=12", "-an", "-f", "null", "-");
|
|
1257
|
+
// Keep HKSV alive during Live View without asking Omni for a second
|
|
1258
|
+
// signed RTSP session. The accessory feeds this fMP4 pipe into the
|
|
1259
|
+
// recording delegate while its normal prebuffer reader is paused.
|
|
1260
|
+
args.push("-map", "0:v:0", "-c:v", "copy", "-bsf:v", "dump_extra=freq=keyframe");
|
|
1261
|
+
if (this.capabilities.hasAudio) {
|
|
1262
|
+
const recordingAudio = this.record?.hksvRecordingConfiguration
|
|
1263
|
+
?.audioCodec;
|
|
1264
|
+
const sampleRate = 48000;
|
|
1265
|
+
const channels = 1;
|
|
1266
|
+
args.push("-map", "0:a:0?", "-c:a", "aac", "-af", "aresample=async=1:first_pts=0", "-ar", String(sampleRate), "-ac", String(channels), "-b:a", `${Math.max(16, Math.min(64, Number(recordingAudio?.bitrate) || 32))}k`);
|
|
1267
|
+
}
|
|
1268
|
+
else {
|
|
1269
|
+
args.push("-an");
|
|
1270
|
+
}
|
|
1271
|
+
args.push("-avoid_negative_ts", "make_zero", "-max_interleave_delta", "0", "-muxdelay", "0", "-muxpreload", "0",
|
|
1272
|
+
// Some Omni firmwares use a long GOP. If we fragment only on source
|
|
1273
|
+
// keyframes, HKSV can receive the initial fragment and then wait past
|
|
1274
|
+
// Apple's recording window even though Live View video is flowing.
|
|
1275
|
+
// Also cut at the Home Hub's negotiated interval so recording keeps
|
|
1276
|
+
// receiving timestamped fMP4 media during the same RTSP session.
|
|
1277
|
+
"-frag_duration", String(Math.max(1000, Math.min(10000, Number(this.record?.hksvRecordingConfiguration
|
|
1278
|
+
?.mediaContainerConfiguration?.fragmentLength) || 4000)) * 1000), "-f", "mp4", "-movflags", "frag_keyframe+empty_moov+default_base_moof+skip_sidx+skip_trailer", "pipe:3");
|
|
1279
|
+
}
|
|
1254
1280
|
return args;
|
|
1255
1281
|
}
|
|
1256
1282
|
startHaCameraProxyPipe(session, process, sourceUrl) {
|
|
@@ -1338,8 +1364,11 @@ export class HomeKitCameraStreamingDelegate extends EventEmitter {
|
|
|
1338
1364
|
}
|
|
1339
1365
|
stopStream(sessionId) {
|
|
1340
1366
|
const session = this.activeSessions.get(sessionId);
|
|
1367
|
+
session?.videoRelay?.close();
|
|
1368
|
+
session?.audioRelay?.close();
|
|
1341
1369
|
if (!session)
|
|
1342
1370
|
return;
|
|
1371
|
+
session.releaseReader?.();
|
|
1343
1372
|
// Clear prepare watchdog timer if still pending
|
|
1344
1373
|
const timer = this.prepareTimeouts.get(sessionId);
|
|
1345
1374
|
if (timer !== undefined) {
|