/* * Copyright (c) 2008 Manuel Traut and Volker Dahnke * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: Manuel Traut */ package YalpOutputs.YalpVlcTelnetOutput; import YalpInterfaces.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*; import java.util.*; import java.io.IOException; /* * Class YalpOutputPluginImpl * * Implements VLC Telnet Streamer as YALP Plugin * * @author Volker Dahnke / Manuel Traut * @version 0.7 10-09-2008 */ public class YalpOutputPluginImpl extends OutputPluginInterfacePOA { private ORB orb; private static Process vlcPlayer = null; private StreamCounter streamCounter= new StreamCounter(); private LinkedList currentStreams = new LinkedList(); private int startPort; private String hostIP; private String vlcCommand; private ServerControlInterface srvCon; private PluginInfo pluginInfo; /* * starts a vlc player in a new process * * @param serverIP * where vlcStreamer is running * @param startport * first port used for streaming * @param vlcCmd * path and name of vlc player executable * * @throws RemoteException * @throws ClassNotFoundException */ public void setORB(ORB _orb) { orb = _orb; pluginInfo = new PluginInfo(); pluginInfo.name = "VLC Telnet Streamer"; pluginInfo.description = "creates streams via VLC players telnet interface"; pluginInfo.type = PluginType.OUTPUT_PLUGIN; pluginInfo.access = new AccessInfo(); pluginInfo.access.name = "stream provided by vlc player"; pluginInfo.access.description = "streams can be displayed with vlc player"; pluginInfo.access.executable = "vlc"; pluginInfo.access.params = ""; pluginInfo.access.type = AccessType.STREAM; /* t.b.d. read vlccmod, startport, hostip from config xml */ String vlcCmd = "/usr/bin/vlc"; vlcCommand = vlcCmd + " --reset-config -I telnet"; startPort = 9000; hostIP = "127.0.0.1"; if(vlcPlayer == null){ try{ vlcPlayer = Runtime.getRuntime().exec(this.vlcCommand); } catch(IOException e){ System.out.println("server.VlcStreamer.java: Streamingserver failed"); } } } public void shutdown() { /* t.b.d. */ } /* * controls Streaming (start, stop, etc) * * @param howtoStream * specifies streaming options */ public void control(OutputHolder howtoStream, YalpErrorHolder err) { switch( howtoStream.value.outputAction.value() ) { case Action._START: start(howtoStream.value); break; case Action._STOP: stop(howtoStream.value); break; case Action._PAUSE: pause(howtoStream.value); break; case Action._PLAY: play(howtoStream.value); break; case Action._FORWARD: next(howtoStream.value); break; //add sth. to current playing stream case Action._CREATE: add(howtoStream.value); break; default: System.out.println("server.VlcStreamer.control: action not supported"); break; } } /* * get plugin infos * * @param PluginInfoHolder (out) * @param YalpErrorHolder (out) */ public void getInfo(PluginInfoHolder info, YalpErrorHolder err) { info = new PluginInfoHolder(); err = new YalpErrorHolder(); err.value.code = YalpErrorCode.OK; info.value = pluginInfo; } /* * request Streaming of submitted Output * * @param stream * which should be streamed * @return Output * extends Information "how to receive" of submitted Output */ public Output request(Output stream) { //stream.setIP(hostIP); for UDP stream.info.name = streamName(); stream.info.params = new Integer(++startPort).toString(); currentStreams.add(stream); return stream; } /** * starts streaming of submitted streamInfo * @param howtoStream */ private void start(Output howtoStream){ /* String newString, setup2; this.streamCounter.actualStreams++; this.streamCounter.allStreams++; switch (howtoStream.info.type.value()){ case AccessType._VOD: newString = "new "+howtoStream.info.name+" vod enabled"; break; case AccessType._BROADCAST: newString = "new "+howtoStream.info.name+" broadcast enabled"; break; default: newString =""; System.out.println("server.VlcStreamer.start: unsupported Type"); break; } String comp = "#transcode{vcodec=mp2v,vb=1024,scale=1,acodec=mpga,ab=192,channels=2}:duplicate{dst="; setup2 = "setup "+howtoStream.info.name+" output "+comp+"std{"; switch (howtoStream.access_type.value()){ case Access._STREAM: setup2 += "access=http,"; break; case Access._UDP: setup2 += "access=udp,"; break; default: System.out.println("server.VlcStreamer.start: unsupported Accesstype"); break; } switch (howtoStream.mux_type.value()){ case Mux._TS: setup2 += "mux=ts,url="+howtoStream.ip+":"+howtoStream.port+"}"; break; case Mux._ES: setup2 += "mux=es,url="+howtoStream.ip+":"+howtoStream.port+"}"; break; case Mux._OGG: setup2 += "mux=ogg,url="+howtoStream.ip+":"+howtoStream.port+"}"; break; default: System.out.println("server.VlcStreamer.start: unsupported Muxer"); break; } // DEBUG COMP setup2 += "}"; String control = "control "+howtoStream.info.name+" play"; // telnet connection TelnetInterface telnet = new TelnetInterface(hostIP, 4212, "admin"); // execute telnet commands telnet.exec(newString); // Playlist String input = ""; for(int i=0; i < howtoStream.list.length; i++){ input = "setup "+howtoStream.info.name+" "; String fileItem = howtoStream.list[i]; fileItem.replace(" ", "\\ "); input += fileItem; telnet.exec(input); } telnet.exec(setup2); telnet.exec(control); // close telnet connection telnet.close(); */ } /** * plays submitted streamInfo * @param howtoStream */ private void play(Output howtoStream){ String control = "control "+howtoStream.info.name+" play"; // telnet connection TelnetInterface telnet = new TelnetInterface(hostIP, 4212, "admin"); telnet.exec(control); // close telnet connection telnet.close(); } /** * pause submitted streamInfo * @param howtoStream */ private void pause(Output howtoStream){ String control = "control "+howtoStream.info.name+" pause"; // DEBUG System.out.println("client.VlcStreamer: Telnetcmd: "); System.out.println(control); // telnet connection TelnetInterface telnet = new TelnetInterface(hostIP, 4212, "admin"); telnet.exec(control); // close telnet connection telnet.close(); } /** * go to next file in playlist * * @param howtoStream */ private void next(Output howtoStream){ String control = "control "+howtoStream.info.name+" seek 100"; // DEBUG System.out.println("client.VlcStreamer: Telnetcmd: "); System.out.println(control); // telnet connection TelnetInterface telnet = new TelnetInterface(hostIP, 4212, "admin"); telnet.exec(control); // close telnet connection telnet.close(); } /** * stop streaming, delete stream * * @param howtoStream */ private void stop(Output howtoStream){ String del = "del "+howtoStream.info.name; this.streamCounter.actualStreams--; // telnet connection TelnetInterface telnet = new TelnetInterface(hostIP, 4212, "admin"); telnet.exec(del); // close telnet connection telnet.close(); currentStreams.remove(howtoStream); } /** * register Stream at vlcPlayer * @param howtoStream */ private void add(Output howtoStream){ String input = ""; // telnet connection TelnetInterface telnet = new TelnetInterface(hostIP, 4212, "admin"); for(int i=0; i < howtoStream.playlist.length; i++){ input += "setup "+howtoStream.info.name+" "; input += howtoStream.playlist[i]; telnet.exec(input); input = ""; } telnet.close(); } /** * calculates streamName * @return String streamName */ private String streamName(){ String streamName = "stream"; streamName += streamCounter.allStreams; return streamName; } /** * stops the streaming server * */ public void quit(){ vlcPlayer.destroy(); } /** * returns the streamcounter * @return StreamCounter */ public StreamCounter getStreamCounter(){ return this.streamCounter; } }