]> git.basschouten.com Git - openhab-addons.git/blob
f479e105212939c9ebb473135dcd1445fa887c81
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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  *
26  * @author Matthew Skinner - Initial contribution
27  */
28
29 @NonNullByDefault
30 public class OpenStreams {
31     private List<StreamOutput> openStreams = Collections.synchronizedList(new ArrayList<StreamOutput>());
32     public String boundary = "thisMjpegStream";
33
34     public synchronized void addStream(StreamOutput stream) {
35         openStreams.add(stream);
36     }
37
38     public synchronized void removeStream(StreamOutput stream) {
39         openStreams.remove(stream);
40     }
41
42     public synchronized int getNumberOfStreams() {
43         return openStreams.size();
44     }
45
46     public synchronized boolean isEmpty() {
47         return openStreams.isEmpty();
48     }
49
50     public synchronized void updateContentType(String contentType, String boundary) {
51         this.boundary = boundary;
52         for (StreamOutput stream : openStreams) {
53             stream.updateContentType(contentType);
54         }
55     }
56
57     public synchronized void queueFrame(byte[] frame) {
58         for (StreamOutput stream : openStreams) {
59             stream.queueFrame(frame);
60         }
61     }
62
63     public synchronized void closeAllStreams() {
64         for (StreamOutput stream : openStreams) {
65             stream.close();
66         }
67         openStreams.clear();
68     }
69 }