2013-08-21

Creating a Wowza Module — the basics

These simple steps don't seem to be covered anywhere, so here's how I started out developing a module for the Wowza Media Server on a remote machine using Netbeans.


The Java Code

The starting Java to test file placement and settings:

package com.example.wowza.modules;

import com.wowza.wms.application.IApplicationInstance;
import com.wowza.wms.module.ModuleBase;

public class TestModule extends ModuleBase {

    public final static String MODULE_NAME = "TestModule";

    public void onAppStart(IApplicationInstance appInstance) {
        getLogger().info("" + MODULE_NAME + " module loaded with application instance");
    }

    public void onAppStop(IApplicationInstance appInstance) {
        getLogger().info("Application instance was stopped, so " + MODULE_NAME + " module has stopped.");
    }

}

That should be enough to inform that the module was started and, by extension, is in the right place.


To get this to compile in Netbeans, you'll need to get hold of both wms-server.jar and log4j-1.2.17.jar from the lib/ directory on the server. You should import these files as libraries to your local Netbeans project. You won't need to move these files around after this.


Transfer the created JAR file from the local project's dist folder to the lib directory on the server.


I used psftp.exe from the makers of PuTTY to transfer the JAR archives between the server and my Windows local machine in both directions.


The Application

Create a test application with these commands:

mkdir applications/testapp
mkdir conf/testapp
cp conf/Application.xml conf/testapp/

Edit the conf/testapp/Application.xml to add this module definition to the <Modules> section before the closing </Modules> element:

<Module>
    <Name>TestModule</Name>
    <Description>A test module</Description>
    <Class>com.example.wowza.modules.TestModule</Class>
</Module>

Testing

Starting an application to test that the module works:
VLC media player: Media -> Open Network Stream -> rtsp://[server_ip]/testapp/mp4:sample.mp4


Checking the access log at logs/wowzamediaserver_access.log should reveal an entry similar to:

2013-08-21   01:43:19        BST     comment      server  INFO    200     -       TestModule module loaded with application  -       -       - (etc.)

It may be buried by lots of access logs regarding the MP4 video we just loaded. Our servers have the wrong time; I am not nocturnal.


Stopping the server will also record the message from onAppStop() into the same log file.


The module was successfully loaded, so all of the relevant pieces are in place to start developing a useful module. This was mainly for my own reference, but hopefully it helped you, too.

No comments:

Post a Comment