commit | author | age
|
60719c
|
1 |
/* |
U |
2 |
AV-Direktor - Control OMXPlayer on Raspberry Pi via HTTP |
|
3 |
Copyright (C) 2021 Ulrich Hilger |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
b16b54
|
17 |
*/ |
229976
|
18 |
package de.uhilger.calypso; |
8e2038
|
19 |
|
U |
20 |
import com.sun.net.httpserver.HttpServer; |
b16b54
|
21 |
import de.uhilger.calypso.handler.BasePlayer; |
229976
|
22 |
import de.uhilger.calypso.handler.CmdHandler; |
b16b54
|
23 |
import de.uhilger.calypso.handler.DBusHandler; |
229976
|
24 |
import de.uhilger.calypso.handler.FileHandler; |
U |
25 |
import de.uhilger.calypso.handler.LogHandler; |
|
26 |
import de.uhilger.calypso.handler.OMXPlayer; |
|
27 |
import de.uhilger.calypso.handler.PingHandler; |
|
28 |
import de.uhilger.calypso.handler.PlayHandler; |
|
29 |
import de.uhilger.calypso.handler.PlayOnHandler; |
|
30 |
import de.uhilger.calypso.handler.SeekHandler; |
|
31 |
import de.uhilger.calypso.handler.StopServerHandler; |
b16b54
|
32 |
import de.uhilger.calypso.handler.VLCKillHandler; |
U |
33 |
import de.uhilger.calypso.handler.VLCPlayer; |
ac496f
|
34 |
import de.uhilger.calypso.handler.VLCSeekHandler; |
8e2038
|
35 |
import java.io.IOException; |
U |
36 |
import java.util.logging.Logger; |
|
37 |
import java.net.InetSocketAddress; |
cd1557
|
38 |
import java.util.concurrent.Executors; |
b16b54
|
39 |
import java.util.logging.Level; |
8e2038
|
40 |
|
U |
41 |
/** |
|
42 |
* |
|
43 |
* @author ulrich |
|
44 |
*/ |
|
45 |
public class Server { |
b16b54
|
46 |
|
8e2038
|
47 |
private static final Logger logger = Logger.getLogger(Server.class.getName()); |
U |
48 |
|
|
49 |
private int port; |
b16b54
|
50 |
|
c2c1fd
|
51 |
private String contextName; |
b16b54
|
52 |
|
8e2038
|
53 |
public Server(int port) { |
U |
54 |
this.port = port; |
|
55 |
} |
b16b54
|
56 |
|
8e2038
|
57 |
public void setPort(int port) { |
U |
58 |
this.port = port; |
|
59 |
} |
b16b54
|
60 |
|
c2c1fd
|
61 |
/** |
b16b54
|
62 |
* |
c2c1fd
|
63 |
* @param contextName e.g. '/calypso' or '/cal' |
U |
64 |
*/ |
|
65 |
public void setContextName(String contextName) { |
|
66 |
this.contextName = contextName; |
|
67 |
} |
b16b54
|
68 |
|
U |
69 |
public void start(String playerType) throws IOException { |
|
70 |
logger.log(Level.INFO, "Server starting on port {0}", port); |
0c8d27
|
71 |
|
8e2038
|
72 |
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); |
b16b54
|
73 |
server.createContext(contextName + "/play", new PlayHandler(BasePlayer.F_PLAY)); |
U |
74 |
if (playerType.equals(App.OMX_PLAYER)) { |
|
75 |
server.createContext(contextName + "/seek", new SeekHandler(OMXPlayer.F_SEEK)); |
|
76 |
server.createContext(contextName + "/stop", new CmdHandler(OMXPlayer.CMD_STOP)); |
|
77 |
server.createContext(contextName + "/pause", new CmdHandler(OMXPlayer.CMD_PAUSE_RESUME)); |
|
78 |
server.createContext(contextName + "/vol-inc", new CmdHandler(OMXPlayer.CMD_INC_VOL)); |
|
79 |
server.createContext(contextName + "/vol-dec", new CmdHandler(OMXPlayer.CMD_DEC_VOL)); |
|
80 |
server.createContext(contextName + "/info", new CmdHandler(OMXPlayer.CMD_TOGGLE_INFO)); |
|
81 |
server.createContext(contextName + "/log", new LogHandler()); |
|
82 |
server.createContext(contextName + "/playon", new PlayOnHandler(OMXPlayer.F_PLAY_ON)); |
|
83 |
} else if (playerType.equals(App.VLC_PLAYER)) { |
|
84 |
server.createContext(contextName + "/pause", new DBusHandler(VLCPlayer.CMD_PAUSE_RESUME)); |
ac496f
|
85 |
//server.createContext(contextName + "/seek", new DBusHandler(VLCPlayer.CMD_SEEK)); |
U |
86 |
server.createContext(contextName + "/seek", new VLCSeekHandler(VLCPlayer.CMD_SEEK)); |
b16b54
|
87 |
server.createContext(contextName + "/stop", new VLCKillHandler()); |
U |
88 |
} |
c2c1fd
|
89 |
server.createContext(contextName + "/ui", new FileHandler(App.getInitParameter(App.IP_WWW_DATA))); |
b16b54
|
90 |
server.createContext(contextName + "/ping", new PingHandler(BasePlayer.F_PING)); |
U |
91 |
server.createContext(contextName + "/server/stop", new StopServerHandler()); |
cd1557
|
92 |
//server.setExecutor(null); // creates a default executor |
U |
93 |
server.setExecutor(Executors.newFixedThreadPool(20)); |
8e2038
|
94 |
server.start(); |
b16b54
|
95 |
} |
8e2038
|
96 |
|
U |
97 |
} |