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.
26 * @author Matthew Skinner - Initial contribution
30 public class OpenStreams {
31 private List<StreamOutput> openStreams = Collections.synchronizedList(new ArrayList<StreamOutput>());
32 public String boundary = "thisMjpegStream";
34 public synchronized void addStream(StreamOutput stream) {
35 openStreams.add(stream);
38 public synchronized void removeStream(StreamOutput stream) {
39 openStreams.remove(stream);
42 public synchronized int getNumberOfStreams() {
43 return openStreams.size();
46 public synchronized boolean isEmpty() {
47 return openStreams.isEmpty();
50 public synchronized void updateContentType(String contentType, String boundary) {
51 this.boundary = boundary;
52 for (StreamOutput stream : openStreams) {
53 stream.updateContentType(contentType);
57 public synchronized void queueFrame(byte[] frame) {
58 for (StreamOutput stream : openStreams) {
59 stream.queueFrame(frame);
63 public synchronized void closeAllStreams() {
64 for (StreamOutput stream : openStreams) {