/* * 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; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; /* * 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; private String log4jFile = "log4j_output_plugin.conf"; private static Logger logger = Logger.getLogger("Yalp.OutputPlugins.VlcTelnetOutput.YalpOutputPluginImpl"); public YalpOutputPluginImpl() { PropertyConfigurator.configureAndWatch(log4jFile); logger.debug("YalpOutputPluginImpl()"); } /* * 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) { logger.debug("setORB()"); 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() { logger.debug("shutdown()"); /* t.b.d. */ } /* * controls Streaming (start, stop, etc) * * @param howtoStream * specifies streaming options */ public void control(OutputHolder howtoStream, YalpErrorHolder err) { logger.debug("control(howtoStream.value.id: "+howtoStream.value.id+")"); YalpError error = new YalpError(); error.descr = ""; error.msg = ""; error.code = YalpErrorCode.OK; error.level = YalpErrorLevel.ERROR_LEVEL_DEBUG; err.value = error; Output output = new Output(); output = howtoStream.value; howtoStream.value = output; 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) { logger.debug("getInfo()"); info = new PluginInfoHolder(); err = new YalpErrorHolder(); err.value.code = YalpErrorCode.OK; info.value = pluginInfo; } /* * register Stream at vlcPlayer * @param howtoStream */ private void add(Output howtoStream){ logger.debug("add()"); String input = ""; TelnetInterface telnet = new TelnetInterface(hostIP, 4212, "admin"); input += "new "+howtoStream.info.name+" broadcast enabled"; for(int i=0; i < howtoStream.playlist.length; i++){ input += " input file://"; input += howtoStream.playlist[i].path + "/"; input += howtoStream.playlist[i].fileName; } telnet.exec(input); telnet.close(); } /* * 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) { logger.debug("request()"); //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) { logger.debug("start()"); String newString, setup2; streamCounter.actualStreams++; streamCounter.allStreams++; switch (howtoStream.info.type.value()) { case AccessType._STREAM: newString = "control "+howtoStream.info.name+" broadcast enabled"; break; default: System.out.println("server.VlcStreamer.start: unsupported Type"); return; } String comp = "#transcode{vcodec=DIV3,vb=256,scale=1,"; comp += "acodec=mpga,ab=192,channels=2}"; comp += ":duplicate{dst="; setup2 = "setup "+howtoStream.info.name+" output "+comp+"std{access=udp,"; setup2 +="mux=ts,"; setup2 +="dst=" + howtoStream.destIp + ":9993";// + howtoStream.info.params; setup2 += "}"; String control = "control "+howtoStream.info.name+" play"; TelnetInterface telnet = new TelnetInterface(hostIP, 4212, "admin"); telnet.exec(newString); telnet.exec(setup2); telnet.exec(control); telnet.close(); } /* * plays submitted streamInfo * @param howtoStream */ private void play(Output howtoStream){ logger.debug("play()"); 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){ logger.debug("pause()"); String control = "control "+howtoStream.info.name+" pause"; logger.debug("client.VlcStreamer: Telnetcmd: " + control); TelnetInterface telnet = new TelnetInterface(hostIP, 4212, "admin"); telnet.exec(control); telnet.close(); } /* * go to next file in playlist * * @param howtoStream */ private void next(Output howtoStream){ logger.debug("next()"); String control = "control "+howtoStream.info.name+" seek 100"; logger.debug("client.VlcStreamer: Telnetcmd: " + control); TelnetInterface telnet = new TelnetInterface(hostIP, 4212, "admin"); telnet.exec(control); telnet.close(); } /* * stop streaming, delete stream * * @param howtoStream */ private void stop(Output howtoStream){ logger.debug("stop()"); String del = "del "+howtoStream.info.name; this.streamCounter.actualStreams--; TelnetInterface telnet = new TelnetInterface(hostIP, 4212, "admin"); telnet.exec(del); telnet.close(); currentStreams.remove(howtoStream); } /* * calculates streamName * @return String streamName */ private String streamName(){ logger.debug("streamName()"); String streamName = "stream"; streamName += streamCounter.allStreams; return streamName; } /* * stops the streaming server * */ public void quit(){ logger.debug("quit()"); vlcPlayer.destroy(); } /* * returns the streamcounter * @return StreamCounter */ public StreamCounter getStreamCounter(){ logger.debug("getStreamCounter()"); return this.streamCounter; } }