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.servlet;
15 import java.util.ArrayList;
16 import java.util.Collections;
17 import java.util.List;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
22 * The {@link OpenStreams} Keeps track of all open mjpeg streams so the byte[] can be given to all FIFO buffers to allow
23 * 1 to many streams without needing to open more than 1 source stream.
25 * @author Matthew Skinner - Initial contribution
28 public class OpenStreams {
29 private List<StreamOutput> openStreams = Collections.synchronizedList(new ArrayList<StreamOutput>());
30 public String boundary = "thisMjpegStream";
32 public synchronized void addStream(StreamOutput stream) {
33 openStreams.add(stream);
36 public synchronized void removeStream(StreamOutput stream) {
37 openStreams.remove(stream);
40 public synchronized int getNumberOfStreams() {
41 return openStreams.size();
44 public synchronized boolean isEmpty() {
45 return openStreams.isEmpty();
48 public synchronized void updateContentType(String contentType, String boundary) {
49 this.boundary = boundary;
50 for (StreamOutput stream : openStreams) {
51 stream.updateContentType(contentType);
55 public synchronized void queueFrame(byte[] frame) {
56 for (StreamOutput stream : openStreams) {
57 stream.queueFrame(frame);
61 public synchronized void closeAllStreams() {
62 for (StreamOutput stream : openStreams) {