/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { EventEmitter } from 'node:stream';
import { SnapshotRequest } from 'homebridge';
import { StreamingDelegate } from './streamingDelegate';
/**
 * possible performance settings:
 * 1. snapshots as current as possible (weak homebridge performance) -> forceRefreshSnapshot
 *    - always get a new image from cloud or cam
 * 2. balanced
 *    - start snapshot refresh but return snapshot as fast as possible
 *      if request takes too long old snapshot will be returned
 * 3. get an old snapshot immediately -> !forceRefreshSnapshot
 *    - wait on cloud snapshot with new events
 *
 * extra options:
 *  - force refresh snapshots with interval
 *  - force immediate snapshot-reject when ringing
 *
 * Drawbacks: elapsed time in homekit might be wrong
 */
export declare class SnapshotManager extends EventEmitter {
    private streamingDelegate;
    private readonly platform;
    private readonly device;
    private readonly accessory;
    private cameraConfig;
    private cameraName;
    private log;
    private livestreamManager;
    private lastCloudSnapshot?;
    private currentSnapshot?;
    private refreshProcessRunning;
    private refreshSnapshotIntervalMinutes;
    private lastEvent;
    private lastRingEvent;
    private lastImageEvent;
    private snapshotRefreshTimer?;
    constructor(streamingDelegate: StreamingDelegate);
    private onRingEvent;
    private onMotionEvent;
    private onPropertyValueChanged;
    getSnapshotBuffer(request: SnapshotRequest): Promise<Buffer>;
    /**
     * Attempts to resolve or reject the promise based on the current snapshot state.
     * @param resolve - The resolve function of the Promise.
     * @param reject - The reject function of the Promise.
     */
    private handleSnapshotResolution;
    /**
     * Sets up a timeout for snapshot retrieval and handles the resolution or rejection.
     * @param resolve - The resolve function of the Promise.
     * @param reject - The reject function of the Promise.
     * @param timeout - The timeout duration in milliseconds.
     */
    private setupSnapshotTimeout;
    /**
     * Sets up an event listener for the 'new snapshot' event.
     * Clears the provided timeout and handles the snapshot resolution.
     * @param resolve - The resolve function of the Promise.
     * @param reject - The reject function of the Promise.
     * @param snapshotTimeout - The timeout object to clear.
     */
    private setupNewSnapshotListener;
    /**
     * Asynchronously retrieves the newest snapshot buffer from the camera.
     * Initiates a snapshot fetch request and waits for the snapshot to be available,
     * with a timeout to handle cases where the snapshot is not received promptly.
     * @returns {Promise<Buffer>} A promise that resolves with the latest snapshot image buffer
     *                            or rejects with an error message if the snapshot is not
     *                            retrieved within the expected time frame.
     */
    private getNewestSnapshotBuffer;
    /**
     * Attempts to retrieve the newest snapshot from the cloud. If a new snapshot is not available
     * within a specified timeout, it either resolves with the current snapshot or rejects.
     * @returns {Promise<Buffer>} A promise that resolves with the newest snapshot.
     */
    private getNewestCloudSnapshot;
    /**
     * Retrieves a balanced snapshot by considering battery impact and data freshness.
     * This function attempts to fetch the newest snapshot, either from the camera or the cloud,
     * depending on the situation and timeout thresholds.
     * @returns {Promise<Buffer>} A promise that resolves with the balanced snapshot image buffer
     *                            or rejects with an error message if the snapshot is not
     *                            retrieved within the expected time frame.
     */
    private getBalancedSnapshot;
    /**
     * Triggers an automatic refresh of the camera snapshot at intervals defined in the camera configuration.
     * If an error occurs during snapshot fetching, it logs a warning.
     */
    private automaticSnapshotRefresh;
    /**
     * Asynchronously retrieves a snapshot from the cloud.
     * If no previous snapshots are available, it sets the last and current snapshots to the fetched image.
     * @returns Promise<void>
     */
    private fetchSnapshotFromCloud;
    /**
     * Fetches the current camera snapshot and updates the current snapshot state.
     * This function will exit early if a refresh process is already running.
     * @returns Promise<void>
     */
    private fetchCurrentCameraSnapshot;
    /**
     * Retrieves the camera source for capturing snapshots.
     *
     * This method determines the appropriate camera source based on the camera configuration
     * and device capabilities. It supports fetching the RTSP stream URL directly from the device
     * if the RTSP service is ready. Otherwise, it attempts to fetch a local live stream source.
     *
     * @returns {Promise<StreamSource>} A promise that resolves to the camera source object.
     * @throws Throws an error if the camera source cannot be determined or retrieved.
     */
    private getCameraSource;
    /**
     * Captures a snapshot from the current camera source.
     *
     * This method first retrieves the current camera source. Depending on the source type (URL or stream),
     * it configures the FFmpeg parameters accordingly. If a delay is configured for the camera snapshot,
     * it sets up the delayed snapshot parameter. The method then uses FFmpeg to capture the snapshot and
     * returns the result as a buffer. If capturing from a live stream, it ensures to stop the live stream
     * after capturing the snapshot or in case of an error.
     *
     * @returns {Promise<Buffer>} A promise that resolves to the snapshot captured as a buffer.
     * @throws Throws an error if no valid camera source is detected or if the snapshot capturing process fails.
     */
    private getCurrentCameraSnapshot;
    /**
     * Resizes a given snapshot image buffer to the specified dimensions.
     *
     * This function utilizes the Sharp library to resize an image buffer. The image is resized
     * to the width and height specified in the SnapshotRequest object. Sharp provides a more
     * efficient and Node.js-native way of handling image processing compared to FFmpeg.
     *
     * @param {Buffer} snapshot - The image buffer to be resized.
     * @param {SnapshotRequest} request - The object containing the desired dimensions.
     * @returns {Promise<Buffer>} A Promise that resolves to the resized image buffer.
     * @throws Will throw an error if the resizing process fails.
     */
    private resizeSnapshot;
}
//# sourceMappingURL=SnapshotManager.d.ts.map