How to access public setVideoSource method of ModuleAVMix from HTTP provider

Hello,

I’ve been trying to access setVideoSource public method of ModuleAVMix but without any success. How can I load module dynamically during runtime and change video source based on query string parameters provided to custom HTTP provider? I want to send stream name with query param and set video/audio source based on provided parameter from HTTP provider using this public method.

IApplication applicationLoc = vhost.getApplication(applicationName);
String appInstanceStr = IApplicationInstance.DEFAULT_APPINSTANCE_NAME;
IApplicationInstance appInstance = applicationLoc.getAppInstance(appInstanceStr);

// get AVMix module instance
String className = "ModuleAVMix";
ModuleAVMix avMixModuleInstance = (ModuleAVMix)appInstance.getModuleInstance(className);

if(avMixModuleInstance != null) {
	// query string parameter
	String queryStr = req.getQueryString();
	if (queryStr == null)
	{
		WMSLoggerFactory.getLogger(CLASS).warn(CLASSNAME+".onHTTPRequest: Query string missing");
		return;
	}

    Map queryMap = HTTPUtils.splitQueryStr(queryStr);
    String streamName = (String) queryMap.get("stream");
	
    // set stream source
	try {
		avMixModuleInstance.setVideoSource("stream1", streamName);
		avMixModuleInstance.setAudioSource("stream1", streamName);
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}

Here is the snippet of code I’ve been trying to use. In the logs I see NullPointerException on the line where I try to get module instance ModuleAVMix avMixModuleInstance = (ModuleAVMix)appInstance.getModuleInstance(className);

Any help or suggestions would be appreciated.

Hi @nika ptskialadze, the className is wrong, needs to be the full class name not just the last part of it.

-so something like com.wowza … ModuleAVMix.

Also, what you really need is to have an HTTPProvider that parses the http request and the query string parameters that you send in that request, and then use the parsed values to initiate an instance of the custom class.

This example code on our GitHub takes an http request, then parses out the values passed in as query string parameters; it then creates a Stream class object for a given application (which is what the AV module is based on).

https://github.com/WowzaMediaSystems/wse-plugin-httpstreamcontrol

You would need to look at the AVModule source code and incorporate the bits that create the Stream class into this example.

Hope that helps!

Please feel free to submit a support ticket if you’d like an engineer to work with you in configuring the pieces together and testing it.