summaryrefslogtreecommitdiff
path: root/src/YalpOutputs
diff options
context:
space:
mode:
Diffstat (limited to 'src/YalpOutputs')
-rw-r--r--src/YalpOutputs/YalpVlcTelnetOutput/TelnetInterface.java147
-rw-r--r--src/YalpOutputs/YalpVlcTelnetOutput/VlcStreamer.java145
-rw-r--r--src/YalpOutputs/YalpVlcTelnetOutput/YalpOutputPluginImpl.java371
-rw-r--r--src/YalpOutputs/YalpVlcTelnetOutput/YalpVlcTelnetOutput.java20
4 files changed, 683 insertions, 0 deletions
diff --git a/src/YalpOutputs/YalpVlcTelnetOutput/TelnetInterface.java b/src/YalpOutputs/YalpVlcTelnetOutput/TelnetInterface.java
new file mode 100644
index 0000000..c8441ac
--- /dev/null
+++ b/src/YalpOutputs/YalpVlcTelnetOutput/TelnetInterface.java
@@ -0,0 +1,147 @@
+/***********************************************************************
+ *
+ * Copyright (c) 2006 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 and Volker Dahnke
+ *
+ ************************************************************************/
+
+package YalpOutputs.YalpVlcTelnetOutput;
+
+import java.net.Socket;
+import java.io.*;
+
+import org.apache.commons.net.telnet.*;
+
+/*******************************************************************************
+*
+* Class TelnetInterface
+*
+* <em>handels telnet connection</em>
+*
+* @author Volker Dahnke / Manuel Traut
+*
+* @version 0.1 20-11-2005<br>
+*
+* @see VlcStreamer
+*
+******************************************************************************/
+public class TelnetInterface {
+
+ private PrintStream out;
+ private InputStream in;
+ private TelnetClient tc = new TelnetClient();
+
+ /**
+ * creates socket, logs on
+ *
+ * @param host
+ * hostname of telnetserver
+ * @param port
+ * destination port
+ * @param pass
+ * password
+ *
+ */
+
+ public TelnetInterface(String host, int port, String pass){
+ try{
+ this.tc.connect(host,port);
+ this.out = new PrintStream(this.tc.getOutputStream());
+ this.in = this.tc.getInputStream();
+ } catch(IOException e){
+ System.out.println("server.TelnetInterface.java: Telnet connection "+host+":"+port+" failed");
+ return;
+ }
+
+ readUntil( "Password:" );
+ write(pass);
+ // Advance to a prompt
+ readUntil("> ");
+ }
+
+ /**
+ * write to TelnetInterface
+ * @param value
+ * String to write to Interface
+ */
+ public void write( String value ) {
+ try {
+ out.println( value );
+ out.flush();
+ System.out.println( value );
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * reads output of telnet client
+ * @param pattern
+ * for stop reading
+ * @return String
+ */
+ public String readUntil( String pattern ) {
+ try {
+ char lastChar = pattern.charAt( pattern.length() - 1 );
+ StringBuffer sb = new StringBuffer();
+ char ch = ( char )in.read();
+ while( true ) {
+ System.out.print( ch );
+ sb.append( ch );
+ if( ch == lastChar ) {
+ if( sb.toString().endsWith( pattern ) ) {
+ return sb.toString();
+ }
+ }
+ ch = ( char )in.read();
+ }
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * executes command
+ * @param cmd
+ * any telnet command
+ * @return String
+ * telnet output caused by the command
+ * null if failed
+ */
+ public String exec(String cmd){
+
+ try {
+ write(cmd);
+ return readUntil( "> " );
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * close telnet connection
+ *
+ * @return boolean
+ * true: connection closed
+ * false: connection close failed
+ */
+
+ public boolean close(){
+ try {
+ this.tc.disconnect();
+ } catch(IOException e){
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/src/YalpOutputs/YalpVlcTelnetOutput/VlcStreamer.java b/src/YalpOutputs/YalpVlcTelnetOutput/VlcStreamer.java
new file mode 100644
index 0000000..568bfb8
--- /dev/null
+++ b/src/YalpOutputs/YalpVlcTelnetOutput/VlcStreamer.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2006 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 and Volker Dahnke
+ */
+
+package YalpOutputs.YalpVlcTelnetOutput;
+
+import YalpInterfaces.*;
+
+import java.io.*;
+import java.util.LinkedList;
+
+import org.omg.CosNaming.*;
+import org.omg.CosNaming.NamingContextPackage.*;
+import org.omg.CORBA.*;
+import org.omg.PortableServer.*;
+import org.omg.PortableServer.POA;
+
+/*
+ *
+ * Class VlcStreamer
+ *
+ * <em>Controlling Streams on a high level</em>
+ *
+ * @author Volker Dahnke / Manuel Traut
+ *
+ * @version 0.6 04-12-2005<br>
+ *
+ * @see InitServer
+ */
+public class VlcStreamer {
+
+ private static ORB orb;
+ private static POA poa;
+ private static YalpOutputPluginImpl streamer;
+ private static OutputPluginInterface outputPlugin;
+ private static ServerControlInterface srvCon;
+ private static 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
+ * @param args
+ * from cmd line
+ */
+ public VlcStreamer(String serverIP, int startport, String vlcCmd,
+ String[] argv) {
+
+ pluginInfo = new PluginInfo();
+ pluginInfo.name = "VLC Telnet Streamer";
+ pluginInfo.description = "creates streams via VLC players telnet interface";
+ pluginInfo.type = PluginType.OUTPUT_PLUGIN;
+ pluginInfo.supportedTypes = new MediaType[0];
+ 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;
+
+ try {
+ this.orb = ORB.init(argv, null);
+ org.omg.CORBA.Object objRef =
+ orb.resolve_initial_references("NameService");
+ NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
+ poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
+ } catch(Exception e) {
+ /* t.b.d. error handling */
+ System.out.println("couldn't host plugin implementation");
+ }
+
+ try {
+ poa.the_POAManager().activate();
+ } catch(org.omg.PortableServer.POAManagerPackage.AdapterInactive e) {
+ /* t.b.d. error handling */
+ System.out.println("poa inactive");
+ }
+/*
+ YalpError error = new YalpError();
+ error.msg = "";
+ error.descr = "";
+ error.code = YalpErrorCode.OK;
+ error.level= YalpErrorLevel.ERROR_LEVEL_INFO;
+ */
+ YalpErrorHolder err = new YalpErrorHolder(/*error*/);
+
+ try {
+ /* only start vlc player if it isn't currently running */
+ org.omg.CORBA.Object objRef =
+ orb.resolve_initial_references("NameService");
+
+ NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
+ String name = "YALP_Server";
+ srvCon = ServerControlInterfaceHelper.narrow(ncRef.resolve_str(name));
+ } catch (Exception e) {
+ System.out.println("Couldn't connect to YALP Server");
+ System.exit(0);
+ }
+
+ streamer = new YalpOutputPluginImpl();
+ streamer.setORB(orb);
+
+ try {
+ poa.activate_object(streamer);
+ org.omg.CORBA.Object ref = poa.servant_to_reference(streamer);
+ outputPlugin = OutputPluginInterfaceHelper.narrow(ref);
+
+ org.omg.CORBA.Object objRef =
+ orb.resolve_initial_references("NameService");
+
+ NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
+ String name = "YALP_Vlc_Telnet_Streamer_Output";
+ NameComponent path[] = ncRef.to_name(name);
+ ncRef.rebind(path, outputPlugin);
+
+ PluginInfoHolder tmp = new PluginInfoHolder(pluginInfo);
+ srvCon.ping(err);
+ System.out.println(err.value.descr);
+ srvCon.registerOutputPlugin(outputPlugin, tmp, err );
+ pluginInfo = tmp.value;
+
+ if(err.value.code != YalpErrorCode.OK)
+ System.out.println("registring outputplugin failed");
+ else
+ System.out.println("output plugin registered");
+
+ orb.run();
+
+ } catch (Exception e) {
+ System.out.println("binding plugin failed 1");
+ e.printStackTrace();
+ System.exit(0);
+ }
+ }
+}
diff --git a/src/YalpOutputs/YalpVlcTelnetOutput/YalpOutputPluginImpl.java b/src/YalpOutputs/YalpVlcTelnetOutput/YalpOutputPluginImpl.java
new file mode 100644
index 0000000..50bdaa4
--- /dev/null
+++ b/src/YalpOutputs/YalpVlcTelnetOutput/YalpOutputPluginImpl.java
@@ -0,0 +1,371 @@
+/*
+ * 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
+ *
+ * <em>Implements VLC Telnet Streamer as YALP Plugin</em>
+ *
+ * @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<Output> currentStreams = new LinkedList<Output>();
+ 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;
+ }
+}
diff --git a/src/YalpOutputs/YalpVlcTelnetOutput/YalpVlcTelnetOutput.java b/src/YalpOutputs/YalpVlcTelnetOutput/YalpVlcTelnetOutput.java
new file mode 100644
index 0000000..766936d
--- /dev/null
+++ b/src/YalpOutputs/YalpVlcTelnetOutput/YalpVlcTelnetOutput.java
@@ -0,0 +1,20 @@
+package YalpOutputs.YalpVlcTelnetOutput;
+
+import YalpInterfaces.*;
+
+public class YalpVlcTelnetOutput {
+
+ public static void main(String[] args) {
+
+ try {
+ System.setProperty("java.security.policy","output.policy");
+ }
+ catch (Exception e) {//DEBUG
+ System.out.println ("Output SecurityManager File not found" + e);
+ System.exit(0);
+ }
+
+ VlcStreamer vlc = new VlcStreamer("localhost", 2501, "/usr/bin/vlc", args);
+ System.out.println("VlcTelnetOutput");
+ }
+}