python-aidot-cameras 1.3.2__py3-none-any.whl → 1.3.4__py3-none-any.whl

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.
@@ -170,10 +170,11 @@ IOTYPE_USER_IPCAM_SPEAKERSTART_WEB_RTC_RESP = 0x353 # 851
170
170
  #: with one byte, 0 for done.
171
171
  IOTYPE_USER_IPCAM_DELLISTEVENT_REQ = 0x4B7
172
172
  IOTYPE_USER_IPCAM_DELLISTEVENT_RESP = 0x4B8
173
- # Card thumbnails (the app's getThumbnais, 0x4b9/0x4ba "custom command") are
174
- # NOT implemented: the camera streams the picture back over a separate native
175
- # TUTK AV channel (avClientStartEx -> avRecvFrameData2), which this library's
176
- # WebRTC/SDES bridge cannot open or read. See docs/PROTOCOL-INVENTORY.md.
173
+ #: Thumbnails of card recordings (the app's getThumbnais, sent as its
174
+ #: "custom command"): 0x4b9 asks for a list of recordings, 0x4ba brings one
175
+ #: picture per reply.
176
+ IOTYPE_USER_IPCAM_SD_THUMBNAIL_REQ = 0x4B9
177
+ IOTYPE_USER_IPCAM_SD_THUMBNAIL_RESP = 0x4BA
177
178
  IOTYPE_USER_IPCAM_HASLISTEVENT_REQ = 0x4B5
178
179
  IOTYPE_USER_IPCAM_HASLISTEVENT_RESP = 0x4B6
179
180
  IOTYPE_USER_IPCAM_PTZ_COMMAND = 0x1001 # 4097
@@ -12,6 +12,7 @@ are all ordinary, and each of them has to arrive in a media browser as an empty
12
12
  list rather than as a traceback.
13
13
  """
14
14
 
15
+ import calendar
15
16
  import logging
16
17
  import struct
17
18
  import time
@@ -21,6 +22,8 @@ from typing import Any, List, Optional
21
22
  from .constants import (
22
23
  IOTYPE_USER_IPCAM_DELLISTEVENT_REQ,
23
24
  IOTYPE_USER_IPCAM_DELLISTEVENT_RESP,
25
+ IOTYPE_USER_IPCAM_SD_THUMBNAIL_REQ,
26
+ IOTYPE_USER_IPCAM_SD_THUMBNAIL_RESP,
24
27
  )
25
28
  from .controls import _session_is_live as _control_session_is_live
26
29
  from .sd_events import (
@@ -427,9 +430,35 @@ class _CameraSdMixin:
427
430
 
428
431
 
429
432
  # --------------------------------------------------------------------------- #
430
- # Deletion of card recordings
433
+ # Thumbnails and deletion of card recordings
431
434
  # --------------------------------------------------------------------------- #
432
435
 
436
+ #: The thumbnail request names recordings by their start as epoch
437
+ #: milliseconds (the app's Long per recording); the reply carries the request
438
+ #: channel, the time back, and the picture.
439
+ _THUMB_HEADER = struct.Struct("<Iq")
440
+
441
+
442
+ def _record_epoch_s(record: Any) -> int:
443
+ """A record's UTC start as epoch SECONDS.
444
+
445
+ The camera matches a thumbnail request against a recording by this value,
446
+ and the app sends epoch seconds (it divides the record's millisecond time
447
+ by 1000 - KVSWebRTCChannel.getThumbnais / SDEventsPresenter). Sending
448
+ milliseconds matches nothing and the camera returns no picture; this cost
449
+ the feature its first ship (2.41.0). Measured live 2026-11-13: seconds
450
+ returns the JPEGs, milliseconds returns empty replies.
451
+ """
452
+ fields = (
453
+ record.year,
454
+ record.month,
455
+ record.day,
456
+ record.hour,
457
+ record.minute,
458
+ record.second,
459
+ )
460
+ return calendar.timegm((*fields, 0, 0, 0))
461
+
433
462
 
434
463
  def _record_stime(record: Any) -> bytes:
435
464
  """A record's start as the TUTK STimeDay the delete request carries."""
@@ -447,6 +476,25 @@ def _record_stime(record: Any) -> bytes:
447
476
  )
448
477
 
449
478
 
479
+ def sd_thumbnail_request(records: "list", channel: int) -> bytes:
480
+ """The 0x4b9 payload: request channel (u32 LE) then each recording's start
481
+ as epoch SECONDS (i64 LE), as the app's getThumbnais builds it."""
482
+ out = struct.pack("<I", channel)
483
+ for r in records:
484
+ out += struct.pack("<q", _record_epoch_s(r))
485
+ return out
486
+
487
+
488
+ def parse_sd_thumbnail(payload: bytes) -> "Optional[tuple[int, int, bytes]]":
489
+ """A 0x4ba reply as (request channel, start epoch seconds, picture bytes), or
490
+ None when it is too short to be one. Read as the app reads it: 4 bytes,
491
+ 8 bytes, then everything else is the picture."""
492
+ if len(payload) < _THUMB_HEADER.size:
493
+ return None
494
+ channel, when = _THUMB_HEADER.unpack_from(payload, 0)
495
+ return channel, when, bytes(payload[_THUMB_HEADER.size :])
496
+
497
+
450
498
  def sd_delete_request(
451
499
  records: "list", *, delete_type: int = 0, event_type: int = 0
452
500
  ) -> bytes:
@@ -462,13 +510,57 @@ def sd_delete_request(
462
510
 
463
511
 
464
512
  class _CameraSdExtrasMixin:
465
- """Deletion for card recordings; mixed into CameraMixin.
513
+ """Thumbnails and deletion for card recordings; mixed into CameraMixin."""
466
514
 
467
- Thumbnails are not here: the app fetches card thumbnails over a separate
468
- native TUTK AV channel (avClientStartEx -> avRecvFrameData2), which this
469
- library's WebRTC/SDES bridge has no equivalent for, so there is no way to
470
- receive the image. See docs/PROTOCOL-INVENTORY.md.
471
- """
515
+ async def async_get_sd_thumbnails(
516
+ self,
517
+ records: "list",
518
+ *,
519
+ session: Any = None,
520
+ timeout: float = 8.0,
521
+ more_timeout: float = 3.0,
522
+ ) -> "dict[Any, bytes]":
523
+ """Pictures for ``records`` (SdEvent), keyed by record, from the camera
524
+ over a live session.
525
+
526
+ The app asks for these from its live screen, which already holds the
527
+ session; a caller here does the same, passing the session or relying
528
+ on the one the serve loop holds. Each reply carries one picture and
529
+ the recording's start it belongs to; a recording the camera has no
530
+ picture for simply gets no reply. Returns what came back, possibly
531
+ nothing: an empty dict means no pictures, not a failure.
532
+ """
533
+ if session is None:
534
+ session = getattr(self, "_stream_session", None)
535
+ if not records or not _session_is_live(session):
536
+ return {}
537
+ by_s = {_record_epoch_s(r): r for r in records}
538
+ channel = (getattr(self, "_sd_thumb_channel", 0) % 1000) + 1
539
+ self._sd_thumb_channel = channel
540
+ try:
541
+ replies = await session.async_avio_request_all(
542
+ IOTYPE_USER_IPCAM_SD_THUMBNAIL_REQ,
543
+ sd_thumbnail_request(records, channel),
544
+ response_cmd=IOTYPE_USER_IPCAM_SD_THUMBNAIL_RESP,
545
+ timeout=timeout,
546
+ more_timeout=more_timeout,
547
+ max_replies=len(records),
548
+ )
549
+ except Exception as exc:
550
+ _LOGGER.debug(
551
+ "SD thumbnails failed for %s: %s", getattr(self, "device_id", "?"), exc
552
+ )
553
+ return {}
554
+ out: "dict[Any, bytes]" = {}
555
+ for reply in replies:
556
+ parsed = parse_sd_thumbnail(reply.payload)
557
+ if parsed is None:
558
+ continue
559
+ _ch, when, picture = parsed
560
+ record = by_s.get(when)
561
+ if record is not None and picture:
562
+ out[record] = picture
563
+ return out
472
564
 
473
565
  async def async_delete_sd_recordings(
474
566
  self,
@@ -1118,6 +1118,22 @@ _BATTERY_STALE_OFFER_GRACE_S = settings.read("AIDOT_BATTERY_STALE_OFFER_GRACE_S"
1118
1118
  _NO_MEDIA_GRACE_S = settings.read("AIDOT_SDES_NO_MEDIA_GRACE_S")
1119
1119
 
1120
1120
 
1121
+ # A faster abandon for ONE first-media shape: the no-probe stall (the camera
1122
+ # answered but its ICE agent sent no STUN probe, so nothing nominates and the
1123
+ # trigger never arms). That shape never recovers - the trigger arms within
1124
+ # about a second of the answer or never - so cycling it to the retry sooner
1125
+ # only helps a weak-link camera (one that stalls this way often, measured on
1126
+ # an A001513) catch a good attempt inside its ~29 s wake window.
1127
+ #
1128
+ # Opt-in and off by default: it only acts when set BELOW the no-media grace; at
1129
+ # the default (equal to _NO_MEDIA_GRACE_S) the check never fires and
1130
+ # _no_media_abandon_due ends the no-probe shape at its own grace exactly as
1131
+ # before, so default behaviour is byte-identical. A slow-but-progressing open
1132
+ # sends probes and gets binding success, so it is never this shape and is never
1133
+ # clipped by a low value.
1134
+ _NO_PROBE_GRACE_S = settings.read("AIDOT_SDES_NO_PROBE_GRACE_S")
1135
+
1136
+
1121
1137
  def _sd_session_mode(sd_playback) -> int:
1122
1138
  """The SESSION_MODE the data channel opens with: LIVING, or SD for playback.
1123
1139
 
@@ -1413,6 +1429,39 @@ def _no_media_abandon_due(*, answered_since_s, grace_s: float, media_pkts: int)
1413
1429
  return media_pkts == 0
1414
1430
 
1415
1431
 
1432
+ def _no_probe_abandon_due(
1433
+ *,
1434
+ answered_since_s,
1435
+ grace_s: float,
1436
+ no_media_grace_s: float,
1437
+ media_pkts: int,
1438
+ nominated: bool,
1439
+ probes: int,
1440
+ binding_success: int,
1441
+ ) -> bool:
1442
+ """Whether a no-probe stall should be abandoned ahead of the no-media grace.
1443
+
1444
+ A targeted, opt-in companion to :func:`_no_media_abandon_due`. It abandons
1445
+ only the no-probe shape (the camera answered but its ICE agent sent no STUN
1446
+ probe, so nothing nominates and the trigger never arms), which never
1447
+ recovers - the trigger arms within about a second of the answer or never -
1448
+ so a weak-link camera that stalls this way often cycles to a fresh offer
1449
+ sooner, inside its ~29 s wake window.
1450
+
1451
+ Off unless ``grace_s`` is set strictly BELOW ``no_media_grace_s``: equal or
1452
+ above, this returns False and :func:`_no_media_abandon_due` ends the shape
1453
+ at its own grace, so default behaviour is unchanged. The shape test is the
1454
+ no-probe branch of :func:`_no_media_shape` (nothing nominated, no probe, no
1455
+ binding success); a slow-but-progressing open sends probes and gets binding
1456
+ success, so it is never this shape and is never clipped.
1457
+ """
1458
+ if grace_s <= 0 or grace_s >= no_media_grace_s or answered_since_s is None:
1459
+ return False
1460
+ if answered_since_s < grace_s or media_pkts != 0:
1461
+ return False
1462
+ return not nominated and probes == 0 and binding_success == 0
1463
+
1464
+
1416
1465
  def _no_media_shape(
1417
1466
  *,
1418
1467
  nominated: bool,
@@ -8366,6 +8415,41 @@ class _SdesOpenMixin:
8366
8415
  and not ps.answer_fut.cancelled()
8367
8416
  ):
8368
8417
  _answered_at = time.monotonic()
8418
+ if _no_probe_abandon_due(
8419
+ answered_since_s=(
8420
+ time.monotonic() - _answered_at
8421
+ if _answered_at is not None
8422
+ else None
8423
+ ),
8424
+ grace_s=_NO_PROBE_GRACE_S,
8425
+ no_media_grace_s=_NO_MEDIA_GRACE_S,
8426
+ media_pkts=int(getattr(_bridge_fn, "_br_media_pkts", 0))
8427
+ + int(getattr(_bridge_fn, "_br_tutk_media", 0)),
8428
+ nominated=bool(
8429
+ _early_nominated
8430
+ or ps._nominated_seen
8431
+ or _bridge_uc_info["sent"]
8432
+ or _bridge_uc_info["prflx"]
8433
+ or (
8434
+ ps._cam_ice_ufrag
8435
+ and ps._cam_ice_pwd
8436
+ and _bridge_uc_info["cands"]
8437
+ )
8438
+ ),
8439
+ probes=len(getattr(_bridge_fn, "_br_probe_verdicts", None) or {}),
8440
+ binding_success=int(
8441
+ getattr(_bridge_fn, "_br_binding_success_count", 0)
8442
+ ),
8443
+ ):
8444
+ # The opt-in fast path for the no-probe shape (see
8445
+ # _no_probe_abandon_due); off unless the grace is set below
8446
+ # _NO_MEDIA_GRACE_S. That shape never recovers, so cycle to
8447
+ # the retry's fresh offer now, while a battery camera is
8448
+ # awake, instead of waiting out the full no-media grace.
8449
+ _stale_offer_abandoned = True
8450
+ _abandoned_by = "no-probe"
8451
+ ps._status(_NO_MEDIA_STATUS["no-probe"] % _NO_PROBE_GRACE_S)
8452
+ break
8369
8453
  if _no_media_abandon_due(
8370
8454
  answered_since_s=(
8371
8455
  time.monotonic() - _answered_at
aidot_cameras/settings.py CHANGED
@@ -351,6 +351,19 @@ KNOBS: "dict[str, Knob]" = _registry(
351
351
  Knob("AIDOT_ABANDONED_MEDIA_GRACE_S", 8.0, "float", reject_below=0.0),
352
352
  Knob("AIDOT_BATTERY_STALE_OFFER_GRACE_S", 15.0, "float"),
353
353
  Knob("AIDOT_SDES_NO_MEDIA_GRACE_S", 20.0, "float"),
354
+ Knob(
355
+ "AIDOT_SDES_NO_PROBE_GRACE_S",
356
+ 20.0,
357
+ "float",
358
+ note=(
359
+ "abandon a no-probe stall (the camera answered but its ICE agent"
360
+ " sent no STUN probe, so nothing nominates) this many seconds after"
361
+ " the answer, instead of the full no-media grace. Opt-in: defaults"
362
+ " to the no-media grace, so it only acts when set lower. A no-probe"
363
+ " stall never recovers, so a weak-link camera that stalls this way"
364
+ " often cycles to a fresh offer faster, inside its ~29 s wake window"
365
+ ),
366
+ ),
354
367
  Knob(
355
368
  "AIDOT_SDES_ECHO_WAIT_S",
356
369
  None,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-aidot-cameras
3
- Version: 1.3.2
3
+ Version: 1.3.4
4
4
  Summary: Control AiDot/Leedarson WiFi lights and cameras (WebRTC streaming, two-way audio, PTZ, controls)
5
5
  Author-email: cbrightly <chris.brightly@gmail.com>
6
6
  License-Expression: MIT
@@ -15,7 +15,7 @@ aidot_cameras/g711.py,sha256=7T4V5oU4d8e9-V85puHCcH2UicOqjwHyZaPti-4lKoQ,3000
15
15
  aidot_cameras/lan_retry.py,sha256=Ba0RxhSKvDY7h_RqYVcpJo2LfHdZl90dtSLgTeY4sVc,30574
16
16
  aidot_cameras/mqtt_config2.py,sha256=say6RSeg-rds4A-rnRBx5-tESI_benzUNlFp6TBVFZA,4915
17
17
  aidot_cameras/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- aidot_cameras/settings.py,sha256=ZaCbTjHZeE-8F8MG_oUwEb7fFZlBzipA1v3xqvaJpSA,21375
18
+ aidot_cameras/settings.py,sha256=RdNl53pcg932d1ard2Pcf6ocCZGhGqPBwnWgIFn5g6s,21970
19
19
  aidot_cameras/_vendor/__init__.py,sha256=FdWQgZCEpTYeOdeC7RcXeYHUloD6e1pw78uoEwBKNFk,215
20
20
  aidot_cameras/_vendor/aiortc/LICENSE,sha256=vsdbWlm7-J6Xnky3ZHdet7XQFnxekHE55vmVNpjIEbY,1502
21
21
  aidot_cameras/_vendor/aiortc/__init__.py,sha256=Mj3egqE6zTGDrCTqet7Qhpe7_ssqGMaXP40kWEV-BOE,2676
@@ -54,7 +54,7 @@ aidot_cameras/camera/__init__.py,sha256=Z-yw5TVoANQUhEfyB-TMObmjkfGS1kOc3PddEjjW
54
54
  aidot_cameras/camera/aac_track.py,sha256=fn038WSG9XLo3Tm0Y0KRyOVQ0rG0IQblrnhAwRqYUUc,18917
55
55
  aidot_cameras/camera/agc.py,sha256=IkLu3skeJkNTxi8Ib3oMH2PYlbxjNpB1UTqpleb7lVg,6752
56
56
  aidot_cameras/camera/client.py,sha256=pzraz3MKHYMNJBnv7sAOcEoVGUEAMG9M1lNpjmsCKF0,363438
57
- aidot_cameras/camera/constants.py,sha256=5GP90PaDoqH_lIXCQ5oH7HwaD17vAd0SRP692jV7zkA,10059
57
+ aidot_cameras/camera/constants.py,sha256=ef2RI380ysGbunF86r5AXFHsTXRwrwWEFGUvgX6Xlig,10007
58
58
  aidot_cameras/camera/controls.py,sha256=3_5vQQXNX4fi-qP91dHM_pAm0JsDOZeHZbeYLEcFIoo,33881
59
59
  aidot_cameras/camera/go2rtc.py,sha256=xGUbmfUouKVpUjkOUprCpcNT1UJcdqnnn_I_yk8yAPs,14104
60
60
  aidot_cameras/camera/h264_sps.py,sha256=MTzsNlV-OufklTdXJC-k9e9BLw0mVTC_mI6o8K932Jc,10197
@@ -68,18 +68,18 @@ aidot_cameras/camera/recording.py,sha256=fDhCRbhwNOcdbZ-F5WT-2jIWZcobPFmUza9Cy3L
68
68
  aidot_cameras/camera/rtp_h264.py,sha256=74Ibw1x0gzTD8JoIvzhAB4IODZ3PSJPTWpKCjKTo838,4593
69
69
  aidot_cameras/camera/rtsp_publish.py,sha256=1tD_GMRJuHmuh9rKGEu_VlhAwW31Ba1IQQY6VthCx2g,83699
70
70
  aidot_cameras/camera/sd_events.py,sha256=q6PorBjD8F5vA1585wv3DGlJ-hl90Wh6PesBijDpN6k,13936
71
- aidot_cameras/camera/sd_listing.py,sha256=AmRvlV-BZtyLEhat_oV47KBvhvY6rD0GL985xozzJOw,20560
71
+ aidot_cameras/camera/sd_listing.py,sha256=XqQ9jHHL1nnjLgotsh48JINj9XtIqxW7ZdlUlTrkJlM,24213
72
72
  aidot_cameras/camera/sd_playback.py,sha256=ptQxho2wY2pTli2jjd4n02J0sFm9Jjre-Wv-jxPZnjI,34233
73
73
  aidot_cameras/camera/sdes.py,sha256=JqEowyAesSrSYYFer_3KzurGTMYw-Sxqj4CXQlN0ZeA,30754
74
- aidot_cameras/camera/sdes_open.py,sha256=JIIzzDqYQB5OndIDXJ_lOPSrx87mOsfHT-lMNUUK9c8,445114
74
+ aidot_cameras/camera/sdes_open.py,sha256=9ydjefIIsOw7pcooOMDaMN74ZB0jra9kxuI9vzLdw80,449254
75
75
  aidot_cameras/camera/ts_fanout.py,sha256=T5qA8aTOWFQJzvE7gE8vfZQjRgg5if5b0V5j2sCqOFA,18893
76
76
  aidot_cameras/camera/ts_tee.py,sha256=4MFDdj4xxFpggj6LLKygsisFgS5aDohcZZWaFLBdhXU,13899
77
77
  aidot_cameras/camera/webrtc.py,sha256=2CLrdcCo1pN93rwODLUnDaSUrNA1kzLdgr7pCUD712Q,12362
78
78
  aidot_cameras/camera/webrtc_open.py,sha256=FuWR_wiMcouWR98HWFYKdsrBHy08LS5QVFKMXWUMwik,229283
79
- python_aidot_cameras-1.3.2.dist-info/licenses/LICENSE,sha256=fh4OpwR6o6ISEqsDcCCaJokiqZw_cjnNrYwXHjmK2OM,1118
80
- python_aidot_cameras-1.3.2.dist-info/licenses/aidot_cameras/_vendor/aiortc/LICENSE,sha256=vsdbWlm7-J6Xnky3ZHdet7XQFnxekHE55vmVNpjIEbY,1502
81
- python_aidot_cameras-1.3.2.dist-info/METADATA,sha256=dYbDr6-_gK6-E3aiwJe89JohOk5Q9NY74_2zPbgZyKo,28787
82
- python_aidot_cameras-1.3.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
83
- python_aidot_cameras-1.3.2.dist-info/entry_points.txt,sha256=3dckqtvsQdFBvgl3i9KoNh5z8THCXDZ3tHxzorTtIZg,61
84
- python_aidot_cameras-1.3.2.dist-info/top_level.txt,sha256=UYMBE_4_Qd_yERQyNLu2ZamsMYRIU4fN_vpHvM0JeCY,14
85
- python_aidot_cameras-1.3.2.dist-info/RECORD,,
79
+ python_aidot_cameras-1.3.4.dist-info/licenses/LICENSE,sha256=fh4OpwR6o6ISEqsDcCCaJokiqZw_cjnNrYwXHjmK2OM,1118
80
+ python_aidot_cameras-1.3.4.dist-info/licenses/aidot_cameras/_vendor/aiortc/LICENSE,sha256=vsdbWlm7-J6Xnky3ZHdet7XQFnxekHE55vmVNpjIEbY,1502
81
+ python_aidot_cameras-1.3.4.dist-info/METADATA,sha256=BM-sVnHTaF-GI49F75kd5geINy3THoSzytLWE4bfUPE,28787
82
+ python_aidot_cameras-1.3.4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
83
+ python_aidot_cameras-1.3.4.dist-info/entry_points.txt,sha256=3dckqtvsQdFBvgl3i9KoNh5z8THCXDZ3tHxzorTtIZg,61
84
+ python_aidot_cameras-1.3.4.dist-info/top_level.txt,sha256=UYMBE_4_Qd_yERQyNLu2ZamsMYRIU4fN_vpHvM0JeCY,14
85
+ python_aidot_cameras-1.3.4.dist-info/RECORD,,