]> git.basschouten.com Git - openhab-addons.git/blob
5045cb36e95061a34b348559c6c7943625c4f056
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.ipcamera.internal.servlet;
14
15 import java.util.ArrayList;
16 import java.util.Collections;
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20
21 /**
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.
24  *
25  * @author Matthew Skinner - Initial contribution
26  */
27 @NonNullByDefault
28 public class OpenStreams {
29     private List<StreamOutput> openStreams = Collections.synchronizedList(new ArrayList<StreamOutput>());
30     public String boundary = "thisMjpegStream";
31
32     public synchronized void addStream(StreamOutput stream) {
33         openStreams.add(stream);
34     }
35
36     public synchronized void removeStream(StreamOutput stream) {
37         openStreams.remove(stream);
38     }
39
40     public synchronized int getNumberOfStreams() {
41         return openStreams.size();
42     }
43
44     public synchronized boolean isEmpty() {
45         return openStreams.isEmpty();
46     }
47
48     public synchronized void updateContentType(String contentType, String boundary) {
49         this.boundary = boundary;
50         for (StreamOutput stream : openStreams) {
51             stream.updateContentType(contentType);
52         }
53     }
54
55     public synchronized void queueFrame(byte[] frame) {
56         for (StreamOutput stream : openStreams) {
57             stream.queueFrame(frame);
58         }
59     }
60
61     public synchronized void closeAllStreams() {
62         for (StreamOutput stream : openStreams) {
63             stream.close();
64         }
65         openStreams.clear();
66     }
67 }