Files
zoneminder/db/zm_update-1.39.29.sql
T
Isaac Connor a6bb811e97 feat: add audio playback control capability and an ONVIF IP speaker module
An IP speaker is controllable but has none of the capabilities the Controls
table models: nothing moves, focuses or lights up. It plays a sound file it
already holds, selected by a numeric id, and carries an output volume.

Add CanAudioPlay, MinAudioFile, MaxAudioFile and CanAudioVolume to Controls,
with migration zm_update-1.39.21.sql. CanAudioPlay renders one button per
sound id plus a stop button; MinAudioFile/MaxAudioFile bound that range;
CanAudioVolume renders the volume pair. The sound id travels in the command
name (audioPlay12), the way presets already do, because a control button has
no way to attach a separate parameter.

Add ZoneMinder::Control::IPSpeaker driving the device's own HTTP interface,
and a Controls entry for it. Playback goes over the vendor interface rather
than ONVIF because the ONVIF audio output service on this firmware only
describes the output and offers no way to start a stored file.

Measured against a device reporting ONVIF Manufacturer "IPSpeaker" and
firmware CS20-V3.3.45N:

- File ids fall in two windows, 10-14 built-in and 20-30 operator uploads.
  Anything else is refused with result -2, and an id in a window with no file
  uploaded with result -3, so valid_fileid refuses only the former: an empty
  slot is a legitimate id the operator may fill later.
- config=audio.set replaces the whole audio section, so a partial write
  reverts the microphone, codec list and echo-cancellation settings. Every
  volume change reads the section and echoes it back with the new level.
  audio.get also returns outmute, which audio.set rejects, so it is excluded
  from the field list.
- The volume reads back and round-trips, but the device's RTSP audio is a
  pre-volume tap of the playback signal: it is unchanged with outvolume at 0,
  so it cannot confirm the loudspeaker's acoustic output. CanAudioVolume is
  set on the strength of the setting persisting, and both the POD and the
  seed row say the acoustic effect is unconfirmed.

The seed row covers the built-in window only, because a fresh device has
nothing uploaded and the firmware refuses an empty slot.

Adding columns to Controls extends the 43 positional INSERTs in
db/controls.sql, which carry no column list and so must match the column
count exactly.

Tests: scripts/ZoneMinder/t/ip_speaker.t, 32 assertions covering file id
windows, volume clamping and stepping, request building and the whole-section
write. All pass.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UvTCzCbvGt8xKQRNCSA7o8
(cherry picked from commit d07e552a3c58373f7f0ccebf9aa28adb4d51baa3)
2026-09-11 20:13:02 -05:00

96 lines
3.1 KiB
SQL

--
-- Add audio playback capabilities to Controls, and an entry for ONVIF IP
-- speakers.
--
-- An IP speaker is controllable but has none of the capabilities the Controls
-- table already models: nothing moves, focuses or lights up. What it does is
-- play a sound file it already holds, selected by a numeric id, and carry an
-- output volume. CanAudioPlay drives the play/stop buttons and the sound
-- selector; MinAudioFile/MaxAudioFile bound that selector; CanAudioVolume
-- drives the volume pair.
--
-- Measured against a device reporting ONVIF Manufacturer "IPSpeaker" and
-- firmware CS20-V3.3.45N. Its file ids fall in two windows, 10-14 for the
-- built-in sounds and 20-30 for operator uploads; the row below covers the
-- built-in window because a fresh device has nothing uploaded and the
-- firmware refuses an empty slot.
--
SELECT 'Checking for CanAudioPlay in Controls';
SET @s = (SELECT IF(
(SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'Controls'
AND table_schema = DATABASE()
AND column_name = 'CanAudioPlay'
) > 0,
"SELECT 'Column CanAudioPlay already exists in Controls'",
"ALTER TABLE `Controls` ADD COLUMN `CanAudioPlay` tinyint(3) unsigned NOT NULL default '0' AFTER `NumScanPaths`"
));
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SELECT 'Checking for MinAudioFile in Controls';
SET @s = (SELECT IF(
(SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'Controls'
AND table_schema = DATABASE()
AND column_name = 'MinAudioFile'
) > 0,
"SELECT 'Column MinAudioFile already exists in Controls'",
"ALTER TABLE `Controls` ADD COLUMN `MinAudioFile` int(10) unsigned default NULL AFTER `CanAudioPlay`"
));
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SELECT 'Checking for MaxAudioFile in Controls';
SET @s = (SELECT IF(
(SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'Controls'
AND table_schema = DATABASE()
AND column_name = 'MaxAudioFile'
) > 0,
"SELECT 'Column MaxAudioFile already exists in Controls'",
"ALTER TABLE `Controls` ADD COLUMN `MaxAudioFile` int(10) unsigned default NULL AFTER `MinAudioFile`"
));
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SELECT 'Checking for CanAudioVolume in Controls';
SET @s = (SELECT IF(
(SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'Controls'
AND table_schema = DATABASE()
AND column_name = 'CanAudioVolume'
) > 0,
"SELECT 'Column CanAudioVolume already exists in Controls'",
"ALTER TABLE `Controls` ADD COLUMN `CanAudioVolume` tinyint(3) unsigned NOT NULL default '0' AFTER `MaxAudioFile`"
));
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SELECT 'Checking for the ONVIF IP Speaker Controls entry';
SET @s = (SELECT IF(
(SELECT COUNT(*)
FROM `Controls`
WHERE `Name` = 'ONVIF IP Speaker'
) > 0,
"SELECT 'ONVIF IP Speaker control already exists'",
"INSERT INTO `Controls` (`Name`,`Type`,`Protocol`,`CanAudioPlay`,`MinAudioFile`,`MaxAudioFile`,`CanAudioVolume`) VALUES ('ONVIF IP Speaker','Ffmpeg','IPSpeaker',1,10,14,1)"
));
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;