2 * Copyright (c) 2010-2021 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>());
33 public synchronized void addStream(StreamOutput stream) {
34 openStreams.add(stream);
37 public synchronized void removeStream(StreamOutput stream) {
38 openStreams.remove(stream);
41 public synchronized int getNumberOfStreams() {
42 return openStreams.size();
45 public synchronized boolean isEmpty() {
46 return openStreams.isEmpty();
49 public synchronized void updateContentType(String contentType) {
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) {