HomeKit Secure-Video cameras need to expose the same services as normal cameras with the following changes:
RTPStreamManagement
service must add the Active
characteristic
(This is used to indicate that the camera is fully turned off)RTPStreamManagement
services was dropped from two to one.MotionSensor
service is required (to indicate movement and thus a start and stop of a recording)CameraOperatingMode
service is requiredDataStreamManagement
service is required (to initiate HomeKit Data Stream communication)CameraEventRecordingManagement
service is required. It needs to link to the MotionSensor
and DataStreamManagement
serviceIf MotionSensor
or OccupancySensor
are added, they must expose the Active
characteristic.
HomeKit Secure-Video doorbells need to expose the same services as both doorbells and secure-video cameras.
Every Secure-Video enabled camera can be set to four different states: Off
, Detect Activity
, Stream
and Stream & Allow Recording
.
Depending on the state the following Active
characteristics for the given services are set.
Camera-States | RTPStreamManagement Active |
CameraOperatingMode HomeKitCameraActive |
CameraEventRecordingManagement Active |
---|---|---|---|
Off | false | false | false |
Detect Activity | false | true | false |
Stream | true | true | false |
Stream & Allow Recording | true | true | true |
Property | Value |
---|---|
UUID | 0000021A-0000-1000-8000-0026BB765291 |
Type | public.hap.service.camera-operating-mode |
Required Characteristics | 3.2 EventSnapshotActive 3.3 HomeKitCameraActive 3.6 PeriodicSnapshotsActive |
Optional Characteristics | 3.4 ManuallyDisabled 3.5 NightVision 3.12 ThirdPartyCameraActive 3.1 CameraOperatingModeIndicator 3.13 Diagonal Field of View |
Property | Value |
---|---|
UUID | 00000204-0000-1000-8000-0026BB765291 |
Type | public.hap.service.camera-recording-management |
Required Characteristics | Active 3.8 SupportedCameraRecordingConfiguration 3.9 SupportedVideoRecordingConfiguration 3.10 SupportedAudioRecordingConfiguration 3.11 SelectedCameraRecordingConfiguration 3.7 RecordingAudioActive |
This characteristic indicates if the camera LED, which shows the current state of the camera (see states), should be turned on. Controlled by "Camera status light" setting in the Home App.
Property | Value |
---|---|
UUID | 0000021D-0000-1000-8000-0026BB765291 |
Type | public.hap.characteristics.camera-operating-mode-indicator |
Permissions | Paired Read, Paired Write, Notify, Timed Write |
Format | bool |
Valid Values | 0 - "Hardware LED is disabled" 1 - "Hardware LED is enabled" |
This characteristic indicates if the option "Camera Settings" -> Notifications -> "Allow Snapshots in Notifications" is turned on. If this option is turned on, a notification from this camera sent to anyone in this home, will include a snapshot of the motion or activity.
Property | Value |
---|---|
UUID | 00000223-0000-1000-8000-0026BB765291 |
Type | public.hap.characteristics.event-snapshots-active |
Permissions | Paired Read, Paired Write, Notify, Timed Write |
Format | bool |
Valid Values | 0 - "Snapshots in notifications are turned off" 1 - "Snapshots in notifications are turned on" |
This characteristic indicates if the camera should detect activity (Unsure if activity just means motion detection or also button presses for doorbell accessories).
Property | Value |
---|---|
UUID | 0000021B-0000-1000-8000-0026BB765291 |
Type | public.hap.characteristics.homekit-camera-active |
Permissions | Paired Read, Paired Write, Notify, Timed Write |
Format | bool |
Valid Values | 0 - "Activity detection should not be enabled" 1 - "Activity detection should be enabled" |
This characteristic indicates if the camera was manually turned off, for example using a physical switch on the camera.
Property | Value |
---|---|
UUID | 00000227-0000-1000-8000-0026BB765291 |
Type | public.hap.characteristics.manually-disabled |
Permissions | Paired Read, Notify |
Format | bool |
Valid Values | 0 - "Camera is not manually disabled" 1 - "Camera was manually disabled" |
This characteristic is already present in the current HAP spec This characteristic indicates if automatic night vision should be turned on.
Property | Value |
---|---|
UUID | 0000011B-0000-1000-8000-0026BB765291 |
Type | public.hap.characteristics.night-vision |
Permissions | Paired Read, Paired Write, Notify |
Format | bool |
Valid Values | 0 - "Disable night-vision mode" 1 - "Enable night-vision mode" |
Exact behaviour unclear. Seems to be always set to true
regardless of anyone viewing periodic snapshots or not.
Property | Value |
---|---|
UUID | 00000225-0000-1000-8000-0026BB765291 |
Type | public.hap.characteristics.periodic-snapshots-active |
Permissions | Paired Read, Paired Write, Notify, Timed Write |
Format | bool |
This characteristic indicates if recordings should include audio.
Property | Value |
---|---|
UUID | 00000226-0000-1000-8000-0026BB765291 |
Type | public.hap.characteristics.recording-audio-active |
Permissions | Paired Read, Paired Write, Notify, Timed Write |
Format | uint8 |
Valid Values | 0 - "Audio should not be included in recordings" 1 - "Audio recording is active" |
Property | Value |
---|---|
UUID | 00000205-0000-1000-8000-0026BB765291 |
Type | public.hap.characteristics.supported-camera-recording-configuration |
Permissions | Paired Read, Notify |
Format | tlv8 |
A read request on this characteristic returns the following structure:
Type | Name | Format | Description |
---|---|---|---|
1 | Prebuffer length | 4 | Size of the prebuffer in milliseconds. It must be at least 4000ms. (typical encountered values: 4000ms, 8000ms) |
2 | Event Trigger Options | 8 | Bitmask of trigger types: 0x01 - Motion 0x02 - Doorbell |
3 | Media Container Configurations | N | List of supported media container configurations. Most cameras out there do only expose one entry. |
Type | Name | Format | Description |
---|---|---|---|
1 | Media Container Type | 1 | Container types: 0 - Fragmented MP4 |
2 | Media Container Parameters | N | Media container parameters |
Type | Name | Format | Description |
---|---|---|---|
1 | Fragment Length | 4 | Length of one mp4 fragment in milliseconds (typically 4000ms) |
Property | Value |
---|---|
UUID | 00000206-0000-1000-8000-0026BB765291 |
Type | public.hap.characteristics.supported-video-recording-configuration |
Permissions | Paired Read, Notify |
Format | tlv8 |
The value of this characteristic is a TLV8-encoded list of supported video codecs:
Type | Name | Format | Description |
---|---|---|---|
1 | Codec Configuration | N | Codec information and the configurations supported for the codec There is one TLV of this type per supported codec |
Type | Name | Format | Description |
---|---|---|---|
1 | Codec | 1 | Type of video codec: 0 - H.264 1 - H-265 |
2 | Video Codec Parameters | N | Video Codec specific parameters |
3 | Video Attributes | N | Video Attributes supported for the codec (tlv list) |
Video Codec Configuration TLV contains exact one tlv of 'Video Codec Parameters' and one entry of 'Video Attributes' per supported resolution/frame rate combination.
Type | Name | Format | Description |
---|---|---|---|
1 | ProfileID | 1 | List of supported H.264 profiles (tlv list is separated by empty tlvs): 0 - Baseline Profile 1 - Main Profile 2 - High Profile |
2 | Level | 1 | List of supported H.264 levels (tlv list is separated by empty tlvs): 0 - 3.1 1 - 3.2 2 - 4 |
3 | Bitrate | 4 | Only present in the Selected Camera Recording Configuration request: Selected video bitrate. Typically, secure video requests 2000kbps when face recognition is enabled, and 800kbps otherwise. |
4 | iFrame_Interval | 4 | Only present in the Selected Camera Recording Configuration request: Selected key frame interval in milliseconds. Typically 4000ms. Seems to be the same value as the fragment length. So every mp4 fragment MUST begin with a keyframe |
Type | Name | Format | Description |
---|---|---|---|
1 | Image width | 2 | Image width in pixels |
2 | Image height | 2 | Image height in pixels |
3 | Frame rate | 1 | Maximum frame rate |
Property | Value |
---|---|
UUID | 00000207-0000-1000-8000-0026BB765291 |
Type | public.hap.characteristics.supported-audio-recording-configuration |
Permissions | Paired Read, Notify |
Format | tlv8 |
The value of this characteristic is a TLV8-encoded list of supported audio codecs:
Type | Name | Format | Description |
---|---|---|---|
1 | Codec Configuration | N | Codec information and the configurations supported for the codec There is one TLV of this type per supported codec |
Type | Name | Format | Description |
---|---|---|---|
1 | Codec | 1 | Type of audio codec: 0 - AAC-LC 1 - AAC-ELD |
2 | Audio Codec Parameters | N | Video Codec specific parameters |
Type | Name | Format | Description |
---|---|---|---|
1 | Channels | 1 | Count of audio channels |
2 | Bitrate Modes | 1 | List (probably empty tlv separated?) of supported audio bitrate modes: 0 - Variable 1 - Constant |
3 | Sample rates | 1 | List (probably empty tlv separated?) of supported sample rates: 0 - 8 kHz 1 - 16 kHz 2 - 24 kHz 3 - 32 kHz 4 - 44.1 kHz 5 - 48 kHz |
4 | Max Audio Bitrate | 4 | Only present in the Selected Camera Recording Configuration request: maximum selected audio bitrate |
Property | Value |
---|---|
UUID | 00000209-0000-1000-8000-0026BB765291 |
Type | public.hap.characteristics.selected-camera-recording-configuration |
Permissions | Paired Read, Paired Write, Notify |
Format | tlv8 |
The structure of the write value looks like the following:
Type | Name | Format | Description |
---|---|---|---|
1 | Selected General Configuration | N | The selected recording configuration |
2 | Selected Video Configuration | N | The selected video recording configuration |
3 | Selected Audio Configuration | N | The selected audio recording configuration |
Usage and behaviour of this characteristic is currently pretty unclear.
Property | Value |
---|---|
UUID | 0000021C-0000-1000-8000-0026BB765291 |
Type | public.hap.characteristics.third-party-camera-active |
Permissions | Paired Read, Notify |
Format | bool |
Property | Value |
---|---|
UUID | 00000224-0000-1000-8000-0026BB765291 |
Type | public.hap.characteristics.diagonal-fov |
Permissions | Paired Read, Notify |
Format | float |
Minimum Value | 0 |
Maximum Value | 360 |
Unit | arcdegrees |
When the camera detects motion it will send a hap event for the characteristic as usual. After that, one of the connected Home Hubs will send an open request.
The header should use dataSend
as the protocol and open
as the topic.
The request has the following message fields:
Key | Type | Description |
---|---|---|
target | string | home hub - to signify the direction of the send |
type | string | ipcamera.recording - the type of the stream |
streamId | int | used to identify this stream; chosen by the home hub |
The response has the following message fields:
Key | Type | Description |
---|---|---|
status | int | Indicates if stream could be opened. Available codes are unknown: 0 - Success |
The header should use dataSend
as the protocol and data
as the topic.
The event has the following message fields:
Key | Type | Description |
---|---|---|
streamId | int | Same identifier used in the dataSend.open |
packets | array | Array of dictionaries. Usually length = 1 |
A packet dictionary looks like the following:
Key | Type | Description |
---|---|---|
data | bytes | Packet data |
metadata | dictionary | Metadata for the packet |
Metadata for recording chunks is defined as:
Key | Type | Description |
---|---|---|
dataType | string | mediaInitialization - for the first event message which contains mp4 initializing ftyp and moof boxes mediaFragment - for all other packets which contains fragmented mp4 segments |
dataSequenceNumber | int | Starting by 1 (with the mediaInitialization packet) and incrementing for every mp4 segment |
dataChunkSequenceNumber | int | Starting by 1 ; enumerates every data chunk of a mp4 segment (if a mp4 segment is to big it can be split in multiple packets using this chunk number) |
isLastDataChunk | boolean | true when the data chunk is the last for the current sequence/mp4 segment |
This event closes the stream and is sent by the home hub once the motion sensor is set back to "No motion detected"
(It seems that the home hub still waits for the last mp4 segment to be sent).
The header should use dataSend
as the protocol and close
as the topic.
The event has the following message fields:
Key | Type | Description |
---|---|---|
streamId | int | Same identifier used in the dataSend.open |
reason | int | Example reasons: 0 - Normal - Normal Close 1 - Not Allowed - Home hub will not allow the Accessory to send this transfer 2 - Busy - Home hub cannot accept this transfer right now 3 - Cancelled - Accessory will not finish the transfer 4 - Unsupported - Home hub does not support this stream type 5 - Unexpected Failure - Some other protocol error occurred and the stream has failed 6 - Timeout - Accessory could not start the session |
The accessory can also send this event message to indicate that the session errored unexpectedly and should be aborted.
The POST body of the POST /resource
request received a new optional property reason
with number type.
With the reason
property a controller indicates the reason for a snapshot request:
0
: Request is the result of a periodic snapshot request.1
: Request is the result of an event snapshot (e.g. to display image for a motion event).If the accessory has PeriodicSnapshotsActive turned off, any snapshot request without
a reason
property or the reason
property set to 0
must be rejected.
If the accessory has EventSnapshotsActive turned off, any snapshot request without
a reason
property or the reason
property set to 1
must be rejected.
When rejecting a snapshot request the accessory must return HTTP 207 Multi-Status
and
a HAP Status code of -70401
(INSUFFICIENT_PRIVILEGES
; if it was rejected due to the missing reason
property)
or -70412
(NOT_ALLOWED_IN_CURRENT_STATE
, if the reason
doesn't match the current set rules).
In this section I will give a brief overlook on how an activity will be recorded using secure-video.
Stream & Allow Recording
prebuffer length
are configuredActive
characteristic of the CameraEventRecordingManagement service will be
set to true (and all other active characteristics getting updated according to the camera state)Motion Detected
characteristic
of the Motion Sensor
to true
dataSend
start
request
with a new streamId.dataSend
data
event with the below listed metadata.
The mp4 data contains a ftyp
and moov
box.
dataSequenceNumber
: 1dataChunkSequenceNumber
: 1isLastDataChunk
: truedataSend
data
events.
The mp4 data contains a moof
and a mdata
box and must start with a keyframe.
The accessory will begin immediately by sending the fragments currently contained in the prebuffer (typically 2x4 seconds in length).
After that the accessory will send any newly recorded mp4 fragments (typically 4s in length) when they become available
(any fragment will be sent, where the recording was started while motion was still detected).dataSequenceNumber
(starting by 2 for the first segment in the preBuffer).
If the size of one mp4 fragment is too big, it can be split into multiple chunks. Then every chunk is enumerated
by the dataChunkSequenceNumber
, while the last chunk must always be marked with isLastDataChunk
equal to true.
Current cameras seems to use a maximum chunk size of 262,144 bytes (or 0x40000 bytes).Motion Detected
characteristic of the Motion Sensor
to false.
The camera will still send out the last mp4 fragment which is currently recorded (remember: typically fixed 4s fragment length).
After a short time the Home Hub will send a dataSend
close
event to indicate that the given
transmission for the streamId
is closed.Example fmp4 files of a transmitted recording can be found in the examples directory. Additionally, a full writeup of the transmitted HomeKit Data Stream payloads for the given example can be found here.