UNPKG

ts-onvif

Version:

Client to ONVIF devices

447 lines (446 loc) 25.4 kB
/** * Media ver20 module * @author Andrew D.Laptev <a.d.laptev@gmail.com> * @see https://www.onvif.org/specs/srv/media/ONVIF-Media2-Service-Spec.pdf * @see http://www.onvif.org/ver20/media/wsdl */ import { Onvif } from './onvif'; import Service from './service'; import { MediaProfile, GetProfiles, CreateProfile, ConfigurationRef, ConfigurationEnumeration, AddConfiguration, RemoveConfiguration, DeleteProfile, GetConfiguration, GetVideoSourceConfigurations, GetAudioEncoderConfigurations, GetVideoEncoderConfigurations, GetAnalyticsConfigurations, GetMetadataConfigurations, GetAudioOutputConfigurations, GetAudioDecoderConfigurations, WebRTCConfiguration, GetStreamUriResponse, GetSnapshotUri, GetSnapshotUriResponse, GetAudioSourceConfigurations, GetVideoEncoderInstances, EncoderInstanceInfo, SetSynchronizationPoint, StartMulticastStreaming, StopMulticastStreaming, GetVideoSourceModes, VideoSourceMode, SetVideoSourceMode, GetOSDs, GetOSDOptions, DeleteOSD, GetMasks, Mask, CreateOSDResponse, CreateMaskResponse, GetMaskOptions, MaskOptions, DeleteMask, Capabilities2 } from './interfaces/media.2'; import { ReferenceToken } from './interfaces/common'; import { AudioDecoderConfiguration, AudioDecoderConfigurationOptions, AudioEncoder2Configuration, AudioEncoderConfigurationOption, AudioOutputConfiguration, AudioOutputConfigurationOptions, AudioSourceConfiguration, AudioSourceConfigurationOptions, MetadataConfiguration, MetadataConfigurationOptions, OSDConfiguration, OSDConfigurationOptions, VideoAnalyticsConfiguration, VideoEncoder2Configuration, VideoEncoder2ConfigurationOptions, VideoSourceConfiguration, VideoSourceConfigurationOptions } from './interfaces/onvif'; /** * Configurations as defined by tr2:ConfigurationEnumeration */ export interface ConfigurationRefExtended extends ConfigurationRef { type: ConfigurationEnumeration; } interface CreateProfileExtended extends CreateProfile { configuration?: ConfigurationRefExtended[]; } interface AddConfigurationExtended extends AddConfiguration { configuration?: ConfigurationRefExtended[]; } interface RemoveConfigurationExtended extends RemoveConfiguration { configuration?: ConfigurationRefExtended[]; } interface GetStreamUri { profileToken?: ReferenceToken; protocol?: 'RtspUnicast' | 'RtspMulticast' | 'RTSP' | 'RtspOverHttp'; } export interface AudioOutputConfigurationExtended extends AudioOutputConfiguration { sendPrimacy: 'www.onvif.org/ver20/HalfDuplex/Server' | 'www.onvif.org/ver20/HalfDuplex/Client' | 'www.onvif.org/ver20/HalfDuplex/Auto'; } /** * Media service, ver20 profile */ export default class Media2 extends Service { constructor(onvif: Onvif); /** * Returns the capabilities of the media service. The result is returned in a typed answer. */ getServiceCapabilities(): Promise<Capabilities2>; /** * Retrieve the profile with the specified token or all defined media profiles. * - If no Type is provided the returned profiles shall contain no configuration information. * - If a single Type with value 'All' is provided the returned profiles shall include all associated configurations. * - Otherwise the requested list of configurations shall for each profile include the configurations present as Type. * @param options * @param options.token Optional token to retrieve exactly one profile. * @param options.type If one or more types are passed only the corresponding configurations will be returned. */ getProfiles({ token, type }?: GetProfiles): Promise<MediaProfile[]>; /** * This operation creates a new media profile. A created profile created via this method may be deleted via the * DeleteProfile method. Optionally Configurations can be assigned to the profile on creation. For details regarding * profile assignment check also the method AddConfiguration. * @param options * @param options.name * @param options.configuration */ createProfile({ name, configuration }: CreateProfileExtended): Promise<ReferenceToken>; /** * This operation adds one or more Configurations to an existing media profile. If a configuration exists in the media * profile, it will be replaced. A device shall support adding a compatible Configuration to a Profile containing a * VideoSourceConfiguration and shall support streaming video data of such a profile. * * Note that OSD elements must be added via the CreateOSD command. * @param options * @param options.profileToken * @param options.name * @param options.configuration */ addConfiguration({ profileToken, name, configuration }: AddConfigurationExtended): Promise<void>; /** * This operation removes one or more configurations from an existing media profile. Tokens appearing in the * configuration list shall be ignored. Presence of the "All" type shall result in an empty profile. Removing a * non-existing configuration shall be ignored and not result in an error. A device supporting the Media2 service * shall support this command * @param options * @param options.profileToken * @param options.configuration */ removeConfiguration({ profileToken, configuration }: RemoveConfigurationExtended): Promise<void>; /** * This operation deletes a profile. The device shall support the deletion of a media profile through the DeletePro- * file command. * A device signaling support for MultiTrackStreaming shall support deleting of virtual profiles via the command. * Note that deleting a profile of a virtual profile set may invalidate the virtual profile. * @param options * @param options.token */ deleteProfile({ token }: DeleteProfile): Promise<void>; /** * Common function to get configurations * @private * @param options * @param options.entityName * @param options.profileToken * @param options.configurationToken */ private getConfigurations; /** * The `getVideoSourceConfigurations` operation allows to retrieve the video source settings of one ore more * configurations. * - If a configuration token is provided the device shall respond with the requested configuration or provide * an error if it does not exist. * - In case only a profile token is provided the device shall respond with all configurations that are compatible * to the provided media profile. * - If no tokens are provided the device shall respond with all available configurations. * @param options * @param options.profileToken * @param options.configurationToken */ getVideoSourceConfigurations(options?: GetVideoSourceConfigurations): Promise<VideoSourceConfiguration[]>; /** * The `getVideoEncoderConfigurations` operation allows to retrieve the video encoder settings of one ore more * configurations. * - If a configuration token is provided the device shall respond with the requested configuration or provide * an error if it does not exist. * - In case only a profile token is provided the device shall respond with all configurations that are compatible * to the provided media profile. * - If no tokens are provided the device shall respond with all available configurations. * @param options * @param options.profileToken * @param options.configurationToken */ getVideoEncoderConfigurations(options?: GetVideoEncoderConfigurations): Promise<VideoEncoder2Configuration[]>; /** * The `getAudioSourceConfigurations` operation allows to retrieve the audio source settings of one ore more * configurations. * - If a configuration token is provided the device shall respond with the requested configuration or provide * an error if it does not exist. * - In case only a profile token is provided the device shall respond with all configurations that are compatible * to the provided media profile. * - If no tokens are provided the device shall respond with all available configurations. * @param options * @param options.profileToken * @param options.configurationToken */ getAudioSourceConfigurations(options?: GetAudioSourceConfigurations): Promise<AudioSourceConfiguration[]>; /** * The `getAudioEncoderConfigurations` operation allows to retrieve the audio encoder settings of one ore more * configurations. * - If a configuration token is provided the device shall respond with the requested configuration or provide * an error if it does not exist. * - In case only a profile token is provided the device shall respond with all configurations that are compatible * to the provided media profile. * - If no tokens are provided the device shall respond with all available configurations. * @param options * @param options.profileToken * @param options.configurationToken */ getAudioEncoderConfigurations(options?: GetAudioEncoderConfigurations): Promise<AudioEncoder2Configuration[]>; /** * The `getAnalyticsConfigurations` operation allows to retrieve the analytics settings of one ore more * configurations. * - If a configuration token is provided the device shall respond with the requested configuration or provide * an error if it does not exist. * - In case only a profile token is provided the device shall respond with all configurations that are compatible * to the provided media profile. * - If no tokens are provided the device shall respond with all available configurations. * @param options * @param options.profileToken * @param options.configurationToken */ getAnalyticsConfigurations(options?: GetAnalyticsConfigurations): Promise<VideoAnalyticsConfiguration[]>; /** * The `getMetadataConfigurations` operation allows to retrieve the metadata settings of one ore more * configurations. * - If a configuration token is provided the device shall respond with the requested configuration or provide * an error if it does not exist. * - In case only a profile token is provided the device shall respond with all configurations that are compatible * to the provided media profile. * - If no tokens are provided the device shall respond with all available configurations. * @param options * @param options.profileToken * @param options.configurationToken */ getMetadataConfigurations(options?: GetMetadataConfigurations): Promise<MetadataConfiguration[]>; /** * The `getAudioOutputConfigurations` operation allows to retrieve the audio output settings of one ore more * configurations. * - If a configuration token is provided the device shall respond with the requested configuration or provide * an error if it does not exist. * - In case only a profile token is provided the device shall respond with all configurations that are compatible * to the provided media profile. * - If no tokens are provided the device shall respond with all available configurations. * @param options * @param options.profileToken * @param options.configurationToken */ getAudioOutputConfigurations(options?: GetAudioOutputConfigurations): Promise<AudioOutputConfigurationExtended[]>; /** * The `getAudioDecoderConfigurations` operation allows to retrieve the audio decoder settings of one ore more * configurations. * - If a configuration token is provided the device shall respond with the requested configuration or provide * an error if it does not exist. * - In case only a profile token is provided the device shall respond with all configurations that are compatible * to the provided media profile. * - If no tokens are provided the device shall respond with all available configurations. * @param options * @param options.profileToken * @param options.configurationToken */ getAudioDecoderConfigurations(options?: GetAudioDecoderConfigurations): Promise<AudioDecoderConfiguration[]>; /** * The `getWebRTCConfigurations` operation allows to retrieve the WebRTC settings of one ore more * configurations. * - If a configuration token is provided the device shall respond with the requested configuration or provide * an error if it does not exist. * - In case only a profile token is provided the device shall respond with all configurations that are compatible * to the provided media profile. * - If no tokens are provided the device shall respond with all available configurations. * @protected Specs not ready yet, this method is for the future development * @experimental */ protected getWebRTCConfigurations(): Promise<WebRTCConfiguration[]>; /** * This operation modifies a video encoder configuration. Running streams using this configuration may be immediately * updated according to the new settings. The changes are not guaranteed to take effect unless the client requests a * new stream URI and restarts any affected stream. NVC methods for changing a running stream are out of scope for * this specification. * SessionTimeout is provided as a hint for keeping rtsp session by a device. If necessary the device may adapt * parameter values for SessionTimeout elements without returning an error. For the time between keep alive calls the * client shall adhere to the timeout value signaled via RTSP. * @param configuration */ setVideoEncoderConfiguration(configuration: VideoEncoder2Configuration): Promise<void>; /** * This operation modifies a video source configuration. Running streams using this configuration may be immediately * updated according to the new settings. The changes are not guaranteed to take effect unless the client requests a * new stream URI and restarts any affected stream. NVC methods for changing a running stream are out of scope for * this specification. * @param configuration */ setVideoSourceConfiguration(configuration: VideoSourceConfiguration): Promise<void>; /** * This operation modifies an audio encoder configuration. Running streams using this configuration may be immediately * updated according to the new settings. The changes are not guaranteed to take effect unless the client requests a * new stream URI and restarts any affected streams. NVC methods for changing a running stream are out of scope for * this specification. * @param configuration */ setAudioEncoderConfiguration(configuration: AudioEncoder2Configuration): Promise<void>; /** * This operation modifies an audio source configuration. Running streams using this configuration may be immediately * updated according to the new settings. The changes are not guaranteed to take effect unless the client requests a * new stream URI and restarts any affected stream NVC methods for changing a running stream are out of scope for this * specification. * @param configuration */ setAudioSourceConfiguration(configuration: AudioSourceConfiguration): Promise<void>; /** * This operation modifies a metadata configuration. Running streams using this configuration may be updated * immediately according to the new settings. The changes are not guaranteed to take effect unless the client requests * a new stream URI and restarts any affected streams. NVC methods for changing a running stream are out of scope for * this specification. * @param configuration */ setMetadataConfiguration(configuration: MetadataConfiguration): Promise<void>; /** * This operation modifies an audio output configuration. * @param configuration */ setAudioOutputConfiguration(configuration: AudioOutputConfigurationExtended): Promise<void>; /** * This operation modifies an audio decoder configuration. * @param configuration */ setAudioDecoderConfiguration(configuration: AudioDecoderConfiguration): Promise<void>; private getConfigurationOptions; /** * This operation returns the available options (supported values and ranges for video source configuration * parameters) when the video source parameters are reconfigured If a video source configuration is specified, the * options shall concern that particular configuration. If a media profile is specified, the options shall be * compatible with that media profile. * @param options */ getVideoSourceConfigurationOptions(options?: GetConfiguration): Promise<VideoSourceConfigurationOptions>; /** * This operation returns the available options (supported values and ranges for video encoder configuration * parameters) when the video encoder parameters are reconfigured. * * This response contains the available video encoder configuration options. If a video encoder configuration is * specified, the options shall concern that particular configuration. If a media profile is specified, the options * shall be compatible with that media profile. If no tokens are specified, the options shall be considered generic * for the device. * @param options */ getVideoEncoderConfigurationOptions(options?: GetConfiguration): Promise<VideoEncoder2ConfigurationOptions[]>; /** * This operation returns the available options (supported values and ranges for audio source configuration * parameters) when the audio source parameters are reconfigured. If an audio source configuration is specified, the * options shall concern that particular configuration. If a media profile is specified, the options shall be * compatible with that media profile. * @param options */ getAudioSourceConfigurationOptions(options?: GetConfiguration): Promise<AudioSourceConfigurationOptions>; /** * This operation returns the available options (supported values and ranges for audio encoder configuration * parameters) when the audio encoder parameters are reconfigured. * @param options */ getAudioEncoderConfigurationOptions(options?: GetConfiguration): Promise<AudioEncoderConfigurationOption[]>; /** * This operation returns the available options (supported values and ranges for metadata configuration parameters) * for changing the metadata configuration. * @param options */ getMetadataConfigurationOptions(options?: GetConfiguration): Promise<MetadataConfigurationOptions>; /** * This operation returns the available options (supported values and ranges for audio output configuration * parameters) for configuring an audio output. To retrieve the EQPresetList, a valid ConfigurationToken must be * provided. If EQPreset is supported and isFrequencyDecibelEditable is signaled as true, the response shall include * the FrequencyDecibelPair. * @param options */ getAudioOutputConfigurationOptions(options?: GetConfiguration): Promise<AudioOutputConfigurationOptions>; /** * This command list the audio decoding capabilities for a given profile and configuration of a device. * @param options */ getAudioDecoderConfigurationOptions(options?: GetConfiguration): Promise<AudioDecoderConfigurationOptions>; /** * The GetVideoEncoderInstances command can be used to request the minimum number of guaranteed video encoder * instances (applications) per Video Source Configuration. * @param options */ getVideoEncoderInstances(options: GetVideoEncoderInstances): Promise<EncoderInstanceInfo>; setSynchronizationPoint({ profileToken }: SetSynchronizationPoint): Promise<void>; /** * This command starts multicast streaming using a specified media profile of a device. Streaming continues until * StopMulticastStreaming is called for the same Profile. The streaming shall continue after a reboot of the device * until a StopMulticastStreaming request is received. The multicast address, port and TTL are configured in the * VideoEncoderConfiguration, AudioEncoderConfiguration and MetadataConfiguration respectively. * @param profileToken */ startMulticastStreaming({ profileToken }?: StartMulticastStreaming): Promise<void>; /** * This command stops multicast streaming using a specified media profile of a device * @param profileToken */ stopMulticastStreaming({ profileToken }?: StopMulticastStreaming): Promise<void>; /** * A device returns the information for current video source mode and settable video source modes of specified video * source. A device that indicates a capability of VideoSourceModes shall support this command. * @param options */ getVideoSourceModes(options?: GetVideoSourceModes): Promise<VideoSourceMode[]>; /** * SetVideoSourceMode changes the media profile structure relating to video source for the specified video source * mode. A device that indicates a capability of VideoSourceModes shall support this command. The behavior after * changing the mode is not defined in this specification. * @param options */ setVideoSourceMode({ videoSourceToken, videoSourceModeToken }: SetVideoSourceMode): Promise<void>; /** * This operation lists existing OSD configurations for the device. * - If an OSD token is provided the device shall respond with the requested configuration or provide an error if it does not exist. * - In case only a video source configuration token is provided the device shall respond with all configurations that exist for the video source configuration. * - If no tokens are provided the device shall respond with all available OSD configurations. * @param options */ getOSDs(options?: GetOSDs): Promise<OSDConfiguration[]>; /** * Set the OSD * @param options */ setOSD(options: OSDConfiguration): Promise<void>; /** * Get the OSD Options. * @param configurationToken */ getOSDOptions({ configurationToken }: GetOSDOptions): Promise<OSDConfigurationOptions>; /** * Create the OSD. * NB!: Unlike the reference implementation, this method returns the generated configuration, since not all * implementations allow you to specify the token yourself; it is often generated on the server side. * @param options */ createOSD(options: OSDConfiguration): Promise<CreateOSDResponse>; /** * Delete the OSD. * @param OSDToken */ deleteOSD({ OSDToken }: DeleteOSD): Promise<void>; /** * This operation lists existing Mask configurations for the device. * - If an Mask token is provided the device shall respond with the requested configuration or provide an error if it does not exist. * - In case only a video source configuration token is provided the device shall respond with all configurations that exist for the video source configuration. * - If no tokens are provided the device shall respond with all available Mask configurations. * @param options */ getMasks(options?: GetMasks): Promise<Mask[]>; /** * Create the Mask. * @param options * @example * const { token } = await cam.media2.createMask({ * type: 'Color', * token: 'mask_token_1', * color: { X: 1, Y: 2, Z: 3, colorspace: 'http://www.onvif.org/ver10/colorspace/YCbCr' }, * configurationToken: 'VideoSourceConfigurationToken_1', * enabled: true, * polygon: { * point: [{ x: 0.1, y: 0.1 }, { x: 0.2, y: 0.2 }, { x: 0.3, y: 0.3 }], * } * }); */ createMask(options: Mask): Promise<CreateMaskResponse>; /** * Set the Mask * @see {@link createMask} * @param options */ setMask(options: Mask): Promise<void>; /** * Get the Mask Options. * @param configurationToken * @example * const res = await cam.media2.getMaskOptions({ configurationToken: 'MaskToken_1' }); * console.log(res.types); */ getMaskOptions({ configurationToken }: GetMaskOptions): Promise<MaskOptions>; /** * Delete the Mask. * @param token */ deleteMask({ token }: DeleteMask): Promise<void>; /** * This operation requests a URI that can be used to initiate a live media stream using RTSP as the control protocol. * The returned URI shall remain valid indefinitely even if the profile is changed. * * Defined stream types are: * RtspUnicast RTSP streaming RTP as UDP Unicast. * RtspMulticast RTSP streaming RTP as UDP Multicast. * RTSP RTSP streaming RTP over TCP. * RtspOverHttp Tunneling both the RTSP control channel and the RTP stream over HTTP or HTTPS. * * If a multicast stream is requested at least one of VideoEncoder2Configuration, AudioEncoder2Configuration and * MetadataConfiguration shall have a valid multicast setting. */ getStreamUri({ protocol, profileToken }: GetStreamUri): Promise<GetStreamUriResponse>; getSnapshotUri(options?: GetSnapshotUri): Promise<GetSnapshotUriResponse>; } export {};