
/*
 * The Media class stores information about a media agent and provides
 * method to start its executable.  Currently the only information the 
 * user is allowed to define is the name and the path of the executable.
 * For each type of media, port number, * transport, and format are 
 * predefined.
 *
 * Author: Janet H. Park
 * Date: August, 1998
 *
 */

import java.io.IOException;

public class Media {

	String name;
	String path;
	String type;
	String port;
	String transport;
	String format;

	public Media(String t, String nm, String p) {
		this.name = nm;
		this.path = p;
		this.type = t;
		if (type.equals("audio")) {
			port = "9090";
			transport = "RTP/AVP";
			format = "0 3 5";
		} else if (type.equals("wb")) {
			type = "application";
			port = "8080";
			transport = "udp";
			format = "wb";
		} else if (type.equals("video")) {
			port = "7070";
			transport = "RTP/AVP";
			format = "26";
		} else
			System.out.println("Media:Unknown media type");
	}

	public String toString() {
		String mstr = type +" "+port+" "+transport+" "+format;
		return (mstr);
	}

	public void start(String ipaddr) {

		String mediacmd[];
		mediacmd = new String[2];
		mediacmd[0] = path + 
		              System.getProperty("file.separator") +
		              name;
		mediacmd[1] = ipaddr + "/" +  port;
		
		System.out.println (mediacmd[0] + " " + mediacmd[1]);
		Process media = null;
		try {
			media = Runtime.getRuntime().exec(mediacmd);
		} catch (IOException e) {
			System.out.println("Error starting media:"+e);
		}
	}

	public String  path() { return path; }
	public String  type() { return type; }
	public String  name() { return name; }
	public String  transport() { return transport; }
	public String  port() { return port; }
	public String  format() { return format; }
	
}
