UNPKG

10.7 kBTypeScriptView Raw
1import { AudioBitrate, VideoCodecType } from ".";
2import { CameraRecordingDelegate, StateChangeDelegate } from "../controller";
3import { DataStreamManagement } from "../datastream";
4import { CameraOperatingMode, CameraRecordingManagement } from "../definitions";
5import { Service } from "../Service";
6import { H264CodecParameters, H264Level, H264Profile, Resolution } from "./RTPStreamManagement";
7/**
8 * Describes options passed to the {@link RecordingManagement}.
9 *
10 * @group Camera
11 */
12export interface CameraRecordingOptions {
13 /**
14 * The size of the prebuffer in milliseconds. It must be at least 4000 ms.
15 * A sensible value for this property is in the interval [4000, 8000].
16 *
17 * In order to provide some context to recording event, it is a good user experience
18 * to also have the recording of a few seconds before the event occurs.
19 * This exactly is the prebuffer. A camera will constantly store the last
20 * x seconds (the `prebufferLength`) to provide more context to a given event.
21 */
22 prebufferLength: number;
23 /**
24 * This property can be used to override the automatic heuristic of the {@link CameraController}
25 * which derives the {@link EventTriggerOption}s from application state.
26 *
27 * {@link EventTriggerOption}s are derived automatically as follows:
28 * * {@link EventTriggerOption.MOTION} is enabled when a {@link Service.MotionSensor} is configured (via {@link CameraControllerOptions.sensors}).
29 * * {@link EventTriggerOption.DOORBELL} is enabled when the {@link DoorbellController} is used.
30 *
31 * Note: This property is **ADDITIVE**. Meaning if the {@link CameraController} decides to add
32 * a certain {@link EventTriggerOption} it will still do so. This option can only be used to
33 * add **additional** {@link EventTriggerOption}s!
34 */
35 overrideEventTriggerOptions?: EventTriggerOption[];
36 /**
37 * List of supported media {@link MediaContainerConfiguration}s (or a single one).
38 */
39 mediaContainerConfiguration: MediaContainerConfiguration | MediaContainerConfiguration[];
40 video: VideoRecordingOptions;
41 audio: AudioRecordingOptions;
42}
43/**
44 * Describes the Event trigger.
45 *
46 * @group Camera
47 */
48export declare const enum EventTriggerOption {
49 /**
50 * The Motion trigger. If enabled motion should trigger the start of a recording.
51 */
52 MOTION = 1,
53 /**
54 * The Doorbell trigger. If enabled a doorbell button press should trigger the start of a recording.
55 *
56 * Note: While the doorbell is defined by the HomeKit specification and HAP-NodeJS supports (and the
57 * {@link RecordingManagement} advertises support for it), HomeKit HomeHubs will (as of now, iOS 15-16)
58 * never enable Doorbell triggers. Seemingly this is currently unsupported by Apple.
59 * See https://github.com/homebridge/HAP-NodeJS/issues/976#issuecomment-1280301989.
60 */
61 DOORBELL = 2
62}
63/**
64 * @group Camera
65 */
66export declare const enum MediaContainerType {
67 FRAGMENTED_MP4 = 0
68}
69/**
70 * @group Camera
71 */
72export interface MediaContainerConfiguration {
73 /**
74 * The type of media container.
75 */
76 type: MediaContainerType;
77 /**
78 * The length in milliseconds of every individual recording fragment.
79 * A typical value of HomeKit Secure Video cameras is 4000ms.
80 */
81 fragmentLength: number;
82}
83/**
84 * @group Camera
85 */
86export interface VideoRecordingOptions {
87 type: VideoCodecType;
88 parameters: H264CodecParameters;
89 /**
90 * Required resolutions to be supported are:
91 * * 1920x1080
92 * * 1280x720
93 *
94 * The following frame rates are required to be supported:
95 * * 15 fps
96 * * 24fps or 30fps
97 */
98 resolutions: Resolution[];
99}
100/**
101 * @group Camera
102 */
103export type AudioRecordingOptions = {
104 /**
105 * List (or single entry) of supported {@link AudioRecordingCodec}s.
106 */
107 codecs: AudioRecordingCodec | AudioRecordingCodec[];
108};
109/**
110 * @group Camera
111 */
112export type AudioRecordingCodec = {
113 type: AudioRecordingCodecType;
114 /**
115 * The count of audio channels. Must be at least `1`.
116 * Defaults to `1`.
117 */
118 audioChannels?: number;
119 /**
120 * The supported bitrate mode. Defaults to {@link AudioBitrate.VARIABLE}.
121 */
122 bitrateMode?: AudioBitrate;
123 samplerate: AudioRecordingSamplerate[] | AudioRecordingSamplerate;
124};
125/**
126 * This type describes the SelectedCameraRecordingConfiguration (written by the device to {@link Characteristic.SelectedCameraRecordingConfiguration}).
127 *
128 * @group Camera
129 */
130export interface CameraRecordingConfiguration {
131 /**
132 * The size of the prebuffer in milliseconds.
133 * This value is less or equal of the value advertised in the {@link Characteristic.SupportedCameraRecordingConfiguration}.
134 */
135 prebufferLength: number;
136 /**
137 * List of the enabled {@link EventTriggerOption}s.
138 */
139 eventTriggerTypes: EventTriggerOption[];
140 /**
141 * The selected {@link MediaContainerConfiguration}.
142 */
143 mediaContainerConfiguration: MediaContainerConfiguration;
144 /**
145 * The selected video codec configuration.
146 */
147 videoCodec: {
148 type: VideoCodecType.H264;
149 parameters: SelectedH264CodecParameters;
150 resolution: Resolution;
151 };
152 /**
153 * The selected audio codec configuration.
154 */
155 audioCodec: AudioRecordingCodec & {
156 bitrate: number;
157 samplerate: AudioRecordingSamplerate;
158 };
159}
160/**
161 * @group Camera
162 */
163export interface SelectedH264CodecParameters {
164 profile: H264Profile;
165 level: H264Level;
166 bitRate: number;
167 /**
168 * The selected i-frame interval in milliseconds.
169 */
170 iFrameInterval: number;
171}
172/**
173 * @group Camera
174 */
175export declare const enum AudioRecordingCodecType {
176 AAC_LC = 0,
177 AAC_ELD = 1
178}
179/**
180 * @group Camera
181 */
182export declare const enum AudioRecordingSamplerate {
183 KHZ_8 = 0,
184 KHZ_16 = 1,
185 KHZ_24 = 2,
186 KHZ_32 = 3,
187 KHZ_44_1 = 4,
188 KHZ_48 = 5
189}
190/**
191 * @group Camera
192 */
193export declare const enum PacketDataType {
194 /**
195 * mp4 moov box
196 */
197 MEDIA_INITIALIZATION = "mediaInitialization",
198 /**
199 * mp4 moof + mdat boxes
200 */
201 MEDIA_FRAGMENT = "mediaFragment"
202}
203/**
204 * @group Camera
205 */
206export interface RecordingPacket {
207 /**
208 * The `Buffer` containing the data of the packet.
209 */
210 data: Buffer;
211 /**
212 * Defines if this `RecordingPacket` is the last one in the recording stream.
213 * If `true` this will signal an end of stream and closes the recording stream.
214 */
215 isLast: boolean;
216}
217/**
218 * @group Camera
219 */
220export interface RecordingManagementServices {
221 recordingManagement: CameraRecordingManagement;
222 operatingMode: CameraOperatingMode;
223 dataStreamManagement: DataStreamManagement;
224}
225/**
226 * @group Camera
227 */
228export interface RecordingManagementState {
229 /**
230 * This property stores a hash of the supported configurations (recording, video and audio) of
231 * the recording management. We use this to determine if the configuration was changed by the user.
232 * If it was changed, we need to discard the `selectedConfiguration` to signify to HomeKit Controllers
233 * that they might reconsider their decision based on the updated configuration.
234 */
235 configurationHash: {
236 algorithm: "sha256";
237 hash: string;
238 };
239 /**
240 * The base64 encoded tlv of the {@link CameraRecordingConfiguration}.
241 * This value MIGHT be `undefined` if no HomeKit controller has yet selected a configuration.
242 */
243 selectedConfiguration?: string;
244 /**
245 * Service `CameraRecordingManagement`; Characteristic `Active`
246 */
247 recordingActive: boolean;
248 /**
249 * Service `CameraRecordingManagement`; Characteristic `RecordingAudioActive`
250 */
251 recordingAudioActive: boolean;
252 /**
253 * Service `CameraOperatingMode`; Characteristic `EventSnapshotsActive`
254 */
255 eventSnapshotsActive: boolean;
256 /**
257 * Service `CameraOperatingMode`; Characteristic `HomeKitCameraActive`
258 */
259 homeKitCameraActive: boolean;
260 /**
261 * Service `CameraOperatingMode`; Characteristic `PeriodicSnapshotsActive`
262 */
263 periodicSnapshotsActive: boolean;
264}
265/**
266 * @group Camera
267 */
268export declare class RecordingManagement {
269 readonly options: CameraRecordingOptions;
270 readonly delegate: CameraRecordingDelegate;
271 private stateChangeDelegate?;
272 private readonly supportedCameraRecordingConfiguration;
273 private readonly supportedVideoRecordingConfiguration;
274 private readonly supportedAudioRecordingConfiguration;
275 /**
276 * 32 bit mask of enabled {@link EventTriggerOption}s.
277 */
278 private readonly eventTriggerOptions;
279 readonly recordingManagementService: CameraRecordingManagement;
280 readonly operatingModeService: CameraOperatingMode;
281 readonly dataStreamManagement: DataStreamManagement;
282 /**
283 * The currently active recording stream.
284 * Any camera only supports one stream at a time.
285 */
286 private recordingStream?;
287 private selectedConfiguration?;
288 /**
289 * Array of sensor services (e.g. {@link Service.MotionSensor} or {@link Service.OccupancySensor}).
290 * Any service in this array owns a {@link Characteristic.StatusActive} characteristic.
291 * The value of the {@link Characteristic.HomeKitCameraActive} is mirrored towards the {@link Characteristic.StatusActive} characteristic.
292 * The array is initialized my the caller shortly after calling the constructor.
293 */
294 sensorServices: Service[];
295 /**
296 * Defines if recording is enabled for this recording management.
297 */
298 private recordingActive;
299 constructor(options: CameraRecordingOptions, delegate: CameraRecordingDelegate, eventTriggerOptions: Set<EventTriggerOption>, services?: RecordingManagementServices);
300 private constructService;
301 private setupServiceHandlers;
302 private handleDataSendOpen;
303 private handleSelectedCameraRecordingConfigurationRead;
304 private handleSelectedCameraRecordingConfigurationWrite;
305 private parseSelectedConfiguration;
306 private _supportedCameraRecordingConfiguration;
307 private _supportedVideoRecordingConfiguration;
308 private _supportedAudioStreamConfiguration;
309 private computeConfigurationHash;
310 /**
311 * @private
312 */
313 serialize(): RecordingManagementState | undefined;
314 /**
315 * @private
316 */
317 deserialize(serialized: RecordingManagementState): void;
318 /**
319 * @private
320 */
321 setupStateChangeDelegate(delegate?: StateChangeDelegate): void;
322 destroy(): void;
323 handleFactoryReset(): void;
324}
325//# sourceMappingURL=RecordingManagement.d.ts.map
\No newline at end of file