Rest api >> wowza 4

Our linux application server is running apache and we control all other boxes from this point using php. We have a RTP >> RTMP audio stream conversion happening successfully on our separate Wowza 4 server.

I’m unsure the best place to look in order to initiate and terminate streams via a RESTful call to wowza from my application server.

From what I could tell in the WowzaStreamingEngine_ServerSideAPI.pdf was that there are http utilities to use to call outside of the wowza box, but I didn’t see any entry points from another server. It seemed like the HTTPProviders don’t work with RTP / RTMP from what I read.

Can you please point me in the right direction on how best to build an HTTP or HTTPS RESTful API from my wowza box that is exposed to HTTP calls from my application server so that I can take my 10+ wowza instances and manage hundreds of streams from my application server?

Many thanks.

Hi,

The REST API is not yet available/exposed. This may be available in the future though, so I will inform our product management team of your interest.

To control streams you could take this approach, that allows you to start and stop streams among other functions.

and to use that effectively review this guide.

Daren

Daren,

Just to confirm then: it is not possible to create my own HTTProviders that could start and stop an RTP pull stream or update SDP files?

Thank you.

Daren - I’ve been able to start and stop a stream using the following code. Can you please let me know if you see any red flags?

package wowzaAPI;
import java.io.*;
import com.wowza.wms.http.*;
import com.wowza.wms.logging.*;
import com.wowza.wms.vhost.*;
import com.wowza.wms.application.*;
public class API extends HTTProvider2Base {
	public void onHTTPRequest(IVHost vhost, IHTTPRequest req, IHTTPResponse resp) {
		if (!doHTTPAuthentication(vhost, req, resp))
			return;
		
		String action = req.getParameter("action");
		String streamName = req.getParameter("streamName");
		String applicationName = req.getParameter("applicationName");
		
		String retStr = "";
		
		if( streamName == null)
		{
			retStr = "<html><head><title>streamName is Required</title></head><body>streamName is Required</body></html>";
		}
		else
		{
			
			if( action == null)
			{
				retStr = "<html><head><title>action parameter is required</title></head><body>action parameter is required</body></html>";
			}
			else if( action.equals( "start" ) )
			{
			
				startMediaCasterStream(vhost, "_definst", streamName, "rtp", applicationName);
				retStr = "<html><head><title>" + streamName
						+ "</title></head><body>" + streamName + " has been started</body></html>";
				
			}
			else if( action.equals( "stop" ) )
			{
				stopMediaCasterStream(vhost, "_definst", streamName, "rtp", applicationName);
				retStr = "<html><head><title>" + streamName
						+ "</title></head><body>" + streamName + " has been stopped</body></html>";
			}
			
		}
		try {
			OutputStream out = resp.getOutputStream();
			byte[] outBytes = retStr.getBytes();
			out.write(outBytes);
		} catch (Exception e) {
			WMSLoggerFactory.getLogger(null).error("API: " + e.toString());
		}
	}
	
	public void startMediaCasterStream(IVHost vhost, String appInstanceStr, String streamName, String mediaCasterType, String applicationName)
	{
		WMSLoggerFactory.getLogger(null).info("WowzaServerWebService.startMediaCasterStream: appInstance:"+appInstanceStr+" streamName:"+streamName+" mediaCasterType:"+mediaCasterType);
		try
		{
			while(true)
			{
				vhost = VHostSingleton.getInstance("_defaultVHost_");
				if (vhost == null)
				{
					WMSLoggerFactory.getLogger(null).warn("WowzaServerWebService.startMediaCasterStream: vhost missing: _defaultVHost_");
					break;
				}
				
				vhost.startApplicationInstance(applicationName, "_definst_");
				
				
				IApplication application = null;
				IApplicationInstance appInstance = null;
				try
				{
					
					application = vhost.getApplication(applicationName);
					if (application == null)
						WMSLoggerFactory.getLogger(null).warn("WowzaServerWebService.startMediaCasterStream: application missing:" + applicationName);
					else
						appInstance = application.getAppInstance("_definst_");
					
					if (appInstance == null)
						WMSLoggerFactory.getLogger(null).warn("WowzaServerWebService.startMediaCasterStream: appInstance missing: _definst_");
				}
				catch(Exception e)
				{	
				}
				
				
				if (appInstance == null)
					break;
				
				appInstance.startMediaCasterStream(streamName, mediaCasterType);
				break;
			}
		}
		catch(Exception e)
		{
			WMSLoggerFactory.getLogger(null).error("WowzaServerWebService.startMediaCasterStream: "+e.toString());
		}		
	}
	public void stopMediaCasterStream(IVHost vhost, String appInstanceStr, String streamName, String mediaCasterType, String applicationName)
	{
		WMSLoggerFactory.getLogger(null).info("WowzaServerWebService.startMediaCasterStream: appInstance:"+appInstanceStr+" streamName:"+streamName+" mediaCasterType:"+mediaCasterType);
		try
		{
			while(true)
			{
				vhost = VHostSingleton.getInstance("_defaultVHost_");
				if (vhost == null)
				{
					WMSLoggerFactory.getLogger(null).warn("WowzaServerWebService.startMediaCasterStream: vhost missing: _defaultVHost_");
					break;
				}
				
				IApplication application = null;
				IApplicationInstance appInstance = null;
				try
				{
					
					application = vhost.getApplication(applicationName);
					if (application == null)
						WMSLoggerFactory.getLogger(null).warn("WowzaServerWebService.startMediaCasterStream: application missing:" + applicationName);
					else
						appInstance = application.getAppInstance("_definst_");
					
					if (appInstance == null)
						WMSLoggerFactory.getLogger(null).warn("WowzaServerWebService.startMediaCasterStream: appInstance missing: _definst_");
				}
				catch(Exception e)
				{	
				}
				
				
				if (appInstance == null)
					break;
				
				appInstance.stopMediaCasterStream(streamName);
				break;
			}
		}
		catch(Exception e)
		{
			WMSLoggerFactory.getLogger(null).error("WowzaServerWebService.startMediaCasterStream: "+e.toString());
		}		
	}
}

For reference here is a photo of what I see in the GUI that does start the stream.

Hi,

Actually yes you can.

This is a very good HTTPProvider example starting point:

That example uses old mediacaster methods, here are more recent examples.

We don’t have a PHP interface example, but this is an example of a Web Service Interface using .NET, just to show you what’s possible and you could just as easily make one for PHP.

Daren