Origin -- Edge -- STB over RTMP: keyframe issue?

Hi!

Setup includes Origin server, Edge server, mag250 STB, and live streams over RTMP.

If stream was already started up when STB connects to play it, everything works fine. So for example streams started with StartupStreams.xml, or streams that were already started and are active on Edge server, works good.

But if this is the first time box requests this stream from Edge (triggering stream startup) - there is no video, only sound on the box. If you move away from this channel and get back to it, while Edge server did not stop the streaming yet, picture will appear.

(Same setup works fine on web players and in VLC, so this issue is specific to mag250 STB and maybe some other boxes)

Is there any setting that will allow Edge server to wait for a keyframe before actually starting streaming to STB, or some buffer, or delay between stream launch on Edge and streaming it out, or anything of this sort, that will allow recently started stream to be fully prepared, before streaming it to the client?

Many thanks.

UPD: Wowza Streaming Engine 4.0.1 and 4.0.3 on Linux and Windows, issue is 100% reproducible

Hi,

You could try

https://www.wowza.com/docs/how-to-fix-unaligned-video-and-audio-with-a-server-side-sort-buffer

Set it to say 2000 then this may help the problem you are seeing.

If that does not work then you would need to lock the edge to the origin , example of which can be found here

https://www.wowza.com/docs/how-to-lock-multi-bitrate-streams-on-live-stream-repeater-edge

Andrew.

The loop until live example will do that.

Richard

The key components of loop until live are a Stream class stream and IMediaStreamActionNotify3.onPublish() and IMediaStreamActionNotify3.onUnPublish() to use as a trigger to switch from file to live source (onPublish) then back to file (onUnPublish).

The source for loop until live example is included in the module collection download if you want to look at that.

There is a lower level API for this shown here.

Richard

Thanks, Alexey

Hi,

It sounds like the STB is possiby timing out its video playback as it has not received any video frames within a certain time after receiving audio, so it thinks it is an audio only stream. It will vary the amount of time to set up from the edge to the origin and it may also be a factor with the STB that it needs a keyframe quite soon after the connection (hard to say).

The only real solution to this would be to have a barker style channel solution - so

  • Using the stream publisher api publish a file to an output stream - Hook 1

  • The STB can always connect to the output stream and it could show your logo or similar

  • When a connection is made to the output stream, this triggers the mediacaster API to get the stream from the origin

  • Using Hook1 switch the content from the barker content to the mediacaster stream to the output

  • Any new connections would just see the output channel as from the origin

  • When no one is watching the output drop back to the barker content and stop the mediacaster connection

It is not too difficult to acheive but would take some work.

Andrew.

Hi Andrew, thank you for the reply.

First approach did not help, while second defeats the whole purpose of Origin-Edge configuration for us. We have multiple Origin servers, and dozens of Edges, and few hundred live channels, we just cant lock Edges to Origins - we need streams to be pulled from Origin to Edge only by demand.

I can add something to the initial input, or rework it a bit.

Case 1. No picture on STB

Origin: stream is up and running, launched from StartupStreams.xls

Edge: stream configured in .stream file, currently not running

Box connects to Edge

Stream starts on Edge

Box has sound but no picture

Case 2. STB has picture

Origin: stream is up and running, launched from StartupStreams.xls

Edge: stream is up and running, launched by previous box connection (and still is up, timeout did not happen yet, or there are more clients “holding” this stream)

Box connects to Edge

Box has sound and picture

Case 3. STB has picture v2

Origin: stream is up and running, launched from StartupStreams.xls

Edge: stream is up and running, launched by previous box connection (and still is up, timeout did not happen yet)

Box connects to Edge

Box has sound and picture

Now we restart Application on Edge

Box looses feed

Application started, box connects to it

Stream starts on Edge

Box has sound and picture

By comparing cases 2 and 3 we see that if box managed to get proper video once, and it did not have a chance to destroy its player instance or reset it (app restart is fast enough, and we did not change channel on the box since last succesful playback) - it starts playback properly from recently launched on the Edge stream.

In case 3, it looks pretty much like box has some crucial piece of data stuck/buffered after first playback, that helps to resume playback properly. It does not work without it. It looks a lot like a keyframe.

The following code on Edge eliminates the issue (obviously not good for production, just a research), so there is definitely something wrong with a stream in the first few seconds after it is being pulled from Origin

UPD: Sometimes eliminates the issue

UPD2: Changing sleep(5000) to sleep(10000) makes it enough to work 10 times from 10

public void play(IClient client, RequestFunction function, AMFDataList params)

{

String stream = getParamString(params, PARAM1);

MediaCasterStreamMap mediaCasterMap = m_appInstance.getMediaCasterStreams();

if (!mediaCasterMap.getStreamManager().streamExists(stream))

m_appInstance.startMediaCasterStream(stream, “liverepeater”);

try

{

Thread.sleep(5000);

}

catch (InterruptedException e)

{

e.printStackTrace();

}

invokePrevious(client, function, params);

}

So question now comes down to what is the event we need to wait for, before starting streaming to mag250 client, when stream is just started.

And can it be fixed with some patch so no need in workarounds?

OR, shell we try to change some settings on Origin?

UPD:

In a normal Edge environment, stream pulling from Origin will not be initialized until invokePrevious in Play()

So waiting for an event is not an option, unless we manually start stream in Play(), and stop/destroy it when there are no clients for it left. It is basically re-doing what Edge is supposed to do, but with this delay added between stream start and streaming to client.

Really need help.

Ok. What kind of criteria can we use instead of Thread.sleep(10000) to be sure stream is absolutely ready, have a keyframe, and so on?

        public void play(IClient client, RequestFunction function, AMFDataList params)
	{
		String stream = getParamString(params, PARAM1);
		MediaCasterStreamMap mediaCasterMap = m_appInstance.getMediaCasterStreams();
		MediaCasterStreamItem mediaCasterItem = null;
		boolean firstLaunch = false;
		if (mediaCasterMap.getMediaCaster(stream) == null)
		{
			firstLaunch = true;
			mediaCasterItem = mediaCasterMap.acquire(stream);
			try
			{
				Thread.sleep(10000);
			}
			catch (InterruptedException e)
			{
				e.printStackTrace();
			}
		}
		invokePrevious(client, function, params);
		if (firstLaunch) mediaCasterItem.release();
	}

Hi Andrew,

everything is clear, except the following:

  • Using Hook1 switch the content from the barker content to the mediacaster stream to the output

How do we do it?

Many thanks, Alex.

The loop until live example will do that.

Richard

Can we have some brief advice on how to do it using Java API, not a ready-made module? We would rather add it into our own module we are using already.

Thank you Richard, great assistance as always