Commit Graph

36 Commits

Author SHA1 Message Date
Sergey Krashevich 78ef8fc064 perf(homekit): optimize motion detector with frame-based timing
Replace time.Now() calls in hot path with frame-based timing:
- Pre-compute triggerLevel (integer comparison instead of float division)
- Calibrate hold/cooldown budgets from FPS (default 30fps)
- Periodic FPS recalibration every 150 frames for accuracy
- Active motion path: 47ns → 3.6ns (13x faster)

Update schema.json with detect mode and motion_threshold.
Add threshold tuning guide to README.
2026-03-05 08:50:27 +03:00
Sergey Krashevich a591186da6 test(homekit): add tests and benchmarks for HDS protocol and HKSV consumer
HDS protocol tests (15 tests, 4 benchmarks):
- Message structure for SendMediaInit and SendMediaFragment
- Multi-chunk splitting for fragments > 256KB
- Chunk boundary handling and sequence preservation
- WriteEvent/WriteResponse/WriteRequest round-trip
- opack helper functions

HKSV consumer tests (14 tests, 3 benchmarks):
- Consumer creation and field initialization
- GOP buffer flush with sequence numbering
- Activate with init segment and seqNum=2
- Activate timeout and error handling
- Stop safety (double-stop, deactivation)
- WriteTo blocking until Stop

Also fixes broken hds_test.go (undefined Client → NewConn).
2026-03-05 06:43:11 +03:00
Sergey Krashevich 1856b7ace4 fix(homekit): fix HKSV recording by correcting HDS protocol and adding GOP buffering
The HKSV recording was failing because:
1. The dataSend.data message structure was wrong - `packets` was a flat integer
   instead of an array of objects with `data` and `metadata` fields matching
   the HAP-NodeJS specification
2. Each video/audio frame was sent as a separate mediaFragment, but Home Hub
   expects GOP-based fragments (~2-4 seconds of accumulated data)
3. Large fragments were not chunked (max 256 KiB per chunk)

Changes:
- Fix HDS dataSend.data message structure to use proper packets array with
  nested data/metadata (dataType, dataSequenceNumber, dataChunkSequenceNumber,
  isLastDataChunk, dataTotalSize)
- Add 256 KiB chunking for large media fragments
- Buffer moof+mdat pairs in hksvConsumer and flush on keyframe boundaries
  (GOP-based fragmentation)
- Pre-start consumer at pair-verify for instant init segment delivery
- Add write-response support to HAP PUT handler for ch131 DataStream setup
- Fix HAP service linking to match HAP-NodeJS reference
- Add default SelectedCameraRecordingConfiguration (ch209) value
- Start continuous motion generator at pair-verify with dedup protection
2026-03-05 06:26:06 +03:00
Sergey Krashevich 35fd1383c8 fix(homekit): adjust motion detection threshold and improve hold time checks 2026-03-05 03:09:02 +03:00
Sergey Krashevich 15b0cc4c0c feat(homekit): implement motion detection with configurable threshold and add motion detector functionality 2026-03-04 15:08:06 +03:00
Sergey Krashevich ab27a042c1 feat(homekit): add HKSV support with motion detection and doorbell functionality
- Introduced HKSV configuration options in homekit.go, allowing for motion detection and doorbell features.
- Implemented API endpoints for triggering motion detection and doorbell events.
- Enhanced server.go to handle HKSV sessions and manage motion detection states.
- Created new accessory types for HKSV and doorbell in accessory.go.
- Added support for audio recording configurations in ch207.go.
- Defined new services for motion detection and doorbell in services_hksv.go.
- Implemented opack encoding/decoding for HDS protocol in opack.go and protocol.go.
- Updated OpenAPI documentation to reflect new endpoints and features.
- Extended schema.json to include HKSV configuration options.
2026-03-04 13:53:17 +03:00
Sergey Krashevich 6304987a26 Review uncommitted changes 2026-02-08 08:50:18 +03:00
Alex X d01b99d105 BIG docs refactoring 2026-02-06 21:45:55 +03:00
Alex X 42e7a03534 Add HomeKit QR code to WebUI #1138 by @mnakada 2025-11-18 20:55:17 +03:00
Alex X 290e8fcfda Add custom category_id for HomeKit server #985 by @Minims 2025-11-18 20:52:32 +03:00
Alex X 6c78b5cb53 Add 404 error for homekit API request 2025-11-18 20:40:30 +03:00
Alex X d053d88ce9 Add support maxwidth/maxheight settings for homekit source 2025-11-11 15:48:12 +03:00
Alex X 5cc32197b8 Fix HomeKit proxy for hass source 2025-11-10 15:35:07 +03:00
Alex X bc1a4ac8e4 Fix API /api/homekit/accessories 2025-11-10 15:34:39 +03:00
Alex X 158f9d3a08 Code refactoring for HomeKit server 2025-11-09 21:58:44 +03:00
Alex X e4359ac217 Rename HomeKit structures according to specs 2025-11-09 21:24:47 +03:00
Alex X 6a4c73db03 Fix possible panic for tlv8.UnmarshalBase64 2025-03-12 06:05:21 +03:00
Alex X a15deedf0d Fix YAML patch in some cases #1626 2025-03-07 21:44:23 +03:00
Alex X 7d37f645ba Improved limited HomeKit server support for open source projects 2025-02-25 19:26:30 +03:00
Alex X 90544ba713 Fix panic for concurrent streams map read and map write #1612 2025-02-24 21:02:33 +03:00
Alex X a9e7a73cc8 Add video bitrate setting for HomeKit source 2024-05-28 22:57:43 +03:00
Alex X 9160403b99 Fix device_id and device_private for HomeKit config 2024-05-12 15:59:50 +03:00
Alex X ae13a72fde Fix mdns log message #843 2023-12-30 20:44:50 +03:00
Alex X 43449e7b08 Fix api port for homekit module 2023-11-18 11:48:19 +03:00
Alex X 2dd47654e6 Fix panic for HomeKit source without SRTP module #712 2023-10-27 17:08:07 +03:00
Sergey Krashevich 9368a6b85e Add conditional check before adding a new pair in the server's AddPair function 2023-09-11 10:34:31 +03:00
Alexey Khit 08dabc7331 Add support HomeKit doorbells 2023-09-02 20:34:39 +03:00
Alexey Khit 5ffd60c429 Update HomeKit default PIN 2023-09-02 14:44:13 +03:00
Alexey Khit 13a7957cf3 Update HomeKit pairing status 2023-09-02 11:05:02 +03:00
Alexey Khit f00e646612 Add support HomeKit server 2023-09-02 06:35:04 +03:00
Alexey Khit 9f404d965f Rewrite HomeKit pairing API 2023-09-01 22:48:06 +03:00
Alexey Khit 22787b979d Rewrite HomeKit client 2023-09-01 10:38:38 +03:00
Alexey Khit 6d82b1ce89 Total rework HAP pkg and HomeKit source 2023-07-23 22:22:36 +03:00
Alexey Khit 73bf96e123 Rewrite mDNS processing 2023-07-11 00:44:27 +03:00
Alexey Khit 0e270081fe Add content-type to API responses 2023-05-30 22:02:16 +03:00
Alexey Khit 75f61b38ac Move cmd module to internal 2023-05-01 12:55:14 +03:00