2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.ipcamera.internal;
15 import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_THRESHOLD_AUDIO_ALARM;
17 import java.util.ArrayList;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.FFmpegFormat;
22 import org.openhab.binding.ipcamera.internal.handler.IpCameraHandler;
23 import org.openhab.core.library.types.DecimalType;
24 import org.openhab.core.library.types.OnOffType;
25 import org.openhab.core.thing.ChannelUID;
26 import org.openhab.core.types.Command;
27 import org.openhab.core.types.RefreshType;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import io.netty.channel.ChannelDuplexHandler;
32 import io.netty.channel.ChannelHandlerContext;
33 import io.netty.util.ReferenceCountUtil;
36 * The {@link HttpOnlyHandler} is responsible for handling commands for generic and onvif thing types.
38 * @author Matthew Skinner - Initial contribution
42 public class HttpOnlyHandler extends ChannelDuplexHandler {
43 private final Logger logger = LoggerFactory.getLogger(getClass());
44 private IpCameraHandler ipCameraHandler;
46 public HttpOnlyHandler(IpCameraHandler handler) {
47 ipCameraHandler = handler;
50 // This handles the incoming http replies back from the camera.
52 public void channelRead(@Nullable ChannelHandlerContext ctx, @Nullable Object msg) throws Exception {
53 ReferenceCountUtil.release(msg);
56 // This handles the commands that come from the Openhab event bus.
57 public void handleCommand(ChannelUID channelUID, Command command) {
58 if (command instanceof RefreshType) {
59 return; // Return as we have handled the refresh command above and don't need to
62 switch (channelUID.getId()) {
63 case CHANNEL_THRESHOLD_AUDIO_ALARM:
64 if (OnOffType.ON.equals(command)) {
65 ipCameraHandler.ffmpegAudioAlarmEnabled = true;
66 } else if (OnOffType.OFF.equals(command) || DecimalType.ZERO.equals(command)) {
67 ipCameraHandler.ffmpegAudioAlarmEnabled = false;
69 ipCameraHandler.ffmpegAudioAlarmEnabled = true;
71 ipCameraHandler.audioThreshold = Integer.valueOf(command.toString());
72 } catch (NumberFormatException e) {
73 logger.warn("Audio Threshold recieved an unexpected command, was it a number?");
76 ipCameraHandler.setupFfmpegFormat(FFmpegFormat.RTSP_ALARMS);
81 // If a camera does not need to poll a request as often as snapshots, it can be
82 // added here. Binding steps through the list and sends 1 every 8 seconds.
83 public ArrayList<String> getLowPriorityRequests() {
84 return new ArrayList<String>(0);