Wowza Community

Dynamically start Streams

Hello,

I am trying to dynamically create and run a live origin/edge application with transcoding for Adaptive bit rate.

I followed the below steps

1- create origin Application.xml (done)

2- create edge Application.xml (done)

3- create .stream files on edge (done)

4- create .smil file on edge (done)

5- add streams to startupstreams.xml on edge (done)

However, in order for it to properly function, I need to either restart the server for the stream to connect from the startupstreams.xml or I have to connect it manually from the engine manager.

How can I connect the stream dynamically, maybe altering another xml file or something ?

Thank you for your replies.

Hi,

There isn’t a way to dynamically start the streams in startupstreams.xml, as you’ve noted that does require a server restart.

But you can programatically start and stop streams in a few ways:

Using the Mediacaster API or by using the code in this guide to build a simple command line interface that you can then use to script the starting and stopping of streams.

Hopefully one of those methods should be useful to you.

I also replied to your support ticket #111963

Daren

Try:

if (!appInstance.getPublishStreamNames().contains("myStream_160p.stream")) {
    appInstance.startMediaCasterStream("myStream_160p.stream", "liverepeater");
}

EDITED: The appInstance.getPublishStreamNames() must NOT contain the stream name before calling appInstance.startMediaCasterStream

Yes, you’re right, sorry for the confusion.

What are you actually trying to achieve?

So why are you using OnAppStart to check if streams are already running? If you check this in OnAppStart, there will logically be no streams running in that application. The only time you need to check if a stream is already running, is when you try to start the stream file. I don’t know how you start the stream file, maybe via an HTTPProvider? You can also maybe check for the existence of a stream in the IMediaStreamActionNotify3.OnPublish (hook onto the IMediaStreamActionNotify3 from the onStreamCreate)

By the way, if I remember correctly, automatic application creation in WSE isn’t officially supported by Wowza. When the REST API gets released officially, your life may get a little easier …

Hello Daren;

Thank you for your reply, I followed your advice and implemented the startMediaCasterStream() method in the onAppStart() event of my custom server module and it worked perfectly.

public void onAppStart(IApplicationInstance appInstance) {

appInstance.startMediaCasterStream(“myStream_160p.stream”, “liverepeater”);

}

However, is there a way to check if the stream is already started before actually starting it in order to prevent starting the same stream twice ?

Thank you for your support.

Hello Karel;

Thank you for your quick response.

if (appInstance.getPublishStreamNames().contains(“myStream_160p.stream”)) <= Does this mean that if the “myStream_160p.stream” is already published? in which case I should do the opposite

if (!appInstance.getPublishStreamNames().contains(“myStream_160p.stream”)) {

//the stream is not started yet … so I start it ?

}

or have I misunderstood?

Aha, I see. Thank you so much for your help.

[Update]

Hello Again;

For more clarification, if you use the above code in the “onAppStart” event directly, it always returns false and starts the stream because onAppStart is still too early and we need to give time for initial streams to start (as explained by Daren - A Wowza engineer).

His advice was to create a separate thread which sleeps for a bit before applying the above code.

So I created a thread which starts all stream files of an application 5 seconds after onAppStart is started.

Upside : Streams are not re-started if a stream for a given application is already started (problem solved)

Downside : We’ll have to wait for someone to actually starts to play for the first time in order to invoke “onAppStart” which in turn starts the streams after 5 seconds. So the first play will return a “playlist not found” error, but will be playable after 5 seconds. But in my case it is not an issue because the first to play the streams in my scenario are stream owners and not end users.

Hello Karel;

I’ve create a superset on top of Wowza to automate application creation, customization and ignition. Which includes actually creating dynamic stream files (and smil for abr) --> Upload them to corresponding edges --> and finally start the stream files as liverepeaters to pull streams from the origin without any human intervention.

The last step is what this thread is all about.