import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
import javax.servlet.AsyncContext;
import javax.servlet.ServletInputStream;
@NonNullByDefault
public class CameraServlet extends IpCameraServlet {
private static final long serialVersionUID = -134658667574L;
+ private static final Dictionary<Object, Object> INIT_PARAMETERS = new Hashtable<>(
+ Map.of("async-supported", "true"));
+
private final IpCameraHandler handler;
public OpenStreams openStreams = new OpenStreams();
private OpenStreams openSnapshotStreams = new OpenStreams();
private OpenStreams openAutoFpsStreams = new OpenStreams();
public CameraServlet(IpCameraHandler handler, HttpService httpService) {
- super(handler, httpService);
+ super(handler, httpService, INIT_PARAMETERS);
this.handler = handler;
}
} else {
output = new StreamOutput(resp, handler.mjpegContentType);
}
+ } else if (handler.mjpegUri.isEmpty() || "ffmpeg".equals(handler.mjpegUri)) {
+ output = new StreamOutput(resp);
} else {
- if (handler.mjpegUri.isEmpty() || "ffmpeg".equals(handler.mjpegUri)) {
- output = new StreamOutput(resp);
- } else {
- ChannelTracking tracker = handler.channelTrackingMap.get(handler.getTinyUrl(handler.mjpegUri));
- if (tracker == null || !tracker.getChannel().isOpen()) {
- logger.debug("Not the first stream requested but the stream from camera was closed");
- handler.openCamerasStream();
- }
- output = new StreamOutput(resp, handler.mjpegContentType);
+ ChannelTracking tracker = handler.channelTrackingMap.get(handler.getTinyUrl(handler.mjpegUri));
+ if (tracker == null || !tracker.getChannel().isOpen()) {
+ logger.debug("Not the first stream requested but the stream from camera was closed");
+ handler.openCamerasStream();
}
+ output = new StreamOutput(resp, handler.mjpegContentType);
}
openStreams.addStream(output);
do {
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Properties;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
private static final long serialVersionUID = 1L;
protected final ThingHandler handler;
protected final HttpService httpService;
+ protected final Dictionary<Object, Object> initParameters;
public IpCameraServlet(ThingHandler handler, HttpService httpService) {
+ this(handler, httpService, new Properties());
+ }
+
+ public IpCameraServlet(ThingHandler handler, HttpService httpService, Dictionary<Object, Object> initParameters) {
this.handler = handler;
this.httpService = httpService;
+ this.initParameters = initParameters;
startListening();
}
public void startListening() {
try {
- httpService.registerServlet("/ipcamera/" + handler.getThing().getUID().getId(), this, null,
+ httpService.registerServlet("/ipcamera/" + handler.getThing().getUID().getId(), this, initParameters,
httpService.createDefaultHttpContext());
} catch (Exception e) {
logger.warn("Registering servlet failed:{}", e.getMessage());