# overriding ModuleBase streaming

**URL:** <https://community.wowza.com/t/overriding-modulebase-streaming/36914>\
**Category:** Wowza Developer Dojo\
**Tags:** wowza-streaming-server-java-api\
**Created:** [July 7, 2011, 2:10am UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914 "2011-07-07T02:10:39Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bogdan\_Coanda](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@Bogdan\_Coanda](https://community.wowza.com/u/Bogdan_Coanda)\
**Post date:** [July 7, 2011, 2:10am UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914/1 "2011-07-07T02:10:39Z")

</div>

Hello, I’ve been having a hard time solving this, so I decided to post here.

What I’m trying to do is basically stream h264+aac content with the addVideoData/addAudioData functions.

I managed so far to implement an IServerNotify2 class that creates a publisher and streams the data correctly, adding the video and audio frames in the publisher.

This works perfectly, but now I’m trying to do the same on a per client basis, in a ModuleBase class as I assume I should.

I manage to take the current stream and add the video/audio data to the stream apparently correct in the play function (meaning that if I grab the current stream from another part of the code and use the ‘createSnapshot’ sample function, I get back perfectly healthy frames).

The problem is the stream never gets sent to the actual player.

In (very) short, what I have now in the module is:

```auto
public class streamer extends ModuleBase
{
    ...
    public void PublishVideo(IMediaStream ims)
    {
        ByteArrayBuffer vc = new ByteArrayBuffer();
        ... // create/get the video data to send
        ims.setVideoTC(DTS, true);
        ims.setVideoSize(vc.size());
        ims.startVideoPacket();
        ims.addVideoData(vc.getRawData(), 0, vc.size());
    }
    public void play(IClient client, RequestFunction function, AMFDataList params)
    {
        IMediaStream ims = client.getAppInstance().getStreams().getStream(client, function.getSrc());
        ... // set stuff on stream
        while(true)
        {
            PublishVideo(ims);
        }
    }
}

```

Now, before anyone asks, the problem isn’t related to the actual video content/headers I pass in, as the same functions are used in the publisher, and that works fine, only difference I see is that in the publisher I have a clientless stream that I get from startup, and I add frames to it through the publisher, and here I’m trying to add frames directly into a client stream I get on ‘play’.

Any suggestions will be welcome 🙂

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [July 7, 2011, 7:10pm UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914/2 "2011-07-07T19:10:34Z")

</div>

You can get to the IMediaStream in play command like this:

```auto
public void play(IClient client, RequestFunction function, AMFDataList params)
    {
        IMediaStream ims = getStream(client, function);
    }

```

And there is higher-level method for injecting metadata:

[https://www.wowza.com/docs/how-to-inject-cue-points-or-metadata](https://www.wowza.com/docs/how-to-inject-cue-points-or-metadata)

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [July 8, 2011, 3:48pm UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914/3 "2011-07-08T15:48:45Z")

</div>

Not sure if I understand. but take a look at IMediaStreamActionNotify2 onPlay handler:

[https://www.wowza.com/docs/imediastreamactionnotify2-example](https://www.wowza.com/docs/imediastreamactionnotify2-example)

Also, the cuepoint example is shown in the context of a Flash controller, but you could factor that out.

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [July 11, 2011, 4:38pm UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914/4 "2011-07-11T16:38:55Z")

</div>

I’m really not sure how to help manufacture a stream in that way. It is very simple to remap a stream in play command:

[https://www.wowza.com/docs/how-to-override-play-to-remap-a-stream-name](https://www.wowza.com/docs/how-to-override-play-to-remap-a-stream-name)

There are things you can do at a low-level in Wowza using Publisher API, but there aren’t any examples like that.

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [July 13, 2011, 3:06pm UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914/5 "2011-07-13T15:06:43Z")

</div>

There are a couple of MediaReader examples on the forum. There is one in the 2nd half of this post:

[https://www.wowza.com/docs/how-to-insert-a-pre-roll-or-mid-roll-for-video-on-demand-playback-in-flash-rtmp-client](https://www.wowza.com/docs/how-to-insert-a-pre-roll-or-mid-roll-for-video-on-demand-playback-in-flash-rtmp-client)

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [July 13, 2011, 3:44pm UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914/6 "2011-07-13T15:44:52Z")

</div>

I am helping as I can, you said you couldn’t find a MediaReader example, but as I said I’m not really sure how to manufacture a stream as you describe. I don’t have experience doing that.

We have a list of consultants you can talk to, some of them probably have this kind of experience. If you want that list, send a request to sales@wowza.com. Include a reference to this thread.

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [November 19, 2012, 1:41pm UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914/7 "2012-11-19T13:41:56Z")

</div>

Nitin,

Take a look at this method:

[https://www.wowza.com/docs/how-to-loop-a-pre-roll-until-a-live-stream-starts-loopuntillive](https://www.wowza.com/docs/how-to-loop-a-pre-roll-until-a-live-stream-starts-loopuntillive)

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [November 20, 2012, 7:55pm UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914/8 "2012-11-20T19:55:47Z")

</div>

Yes, in the streamschedule.smil /playlist set repeat=“false”

```auto
<smil>
    <head>
    </head>
    <body>
        <stream name="Stream1"></stream>
        
        <playlist name="pl1" playOnStream="Stream1" repeat="false" scheduled="2009-12-11 16:00:00">
            <video src="mp4:sample.mp4" start="0" length="20"/>
        </playlist>
    </body>
</smil>

```

Richard

---

<div class="post-metadata">

**Author:** ![Sorin\_Vasilescu](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Sorin\_Vasilescu](https://community.wowza.com/u/Sorin_Vasilescu)\
**Post date:** [July 14, 2011, 9:39am UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914/9 "2011-07-14T09:39:34Z")

</div>

Thank you for your help, Richard. Exelle and I are working together, I will contact sales regarding this issue.

---

<div class="post-metadata">

**Author:** ![Bogdan\_Coanda](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@Bogdan\_Coanda](https://community.wowza.com/u/Bogdan_Coanda)\
**Post date:** [July 7, 2011, 11:05pm UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914/10 "2011-07-07T23:05:41Z")

</div>

From what I understand, the cuepoint example inserts data on the client’s request. I’m trying to override the normal streaming i.e. send my own frames in the stream instead of the requested content.

What I wrote above adds the frames to the stream, but blocks the rest of the circuit until done, so the player(LivePlayer,PlaylistPlayer,etc) associated with the stream never sends the actual frames to the client. In comparison, in a normal module, ‘play’ would get called, do some stuff, finish, and afterwards a player in background handles sending the content to the client. I think I need to implement a callback that would get called when the frames are just about to be sent to the client, and override it there, or tell the stream to use my own receiver instead of, for example, the LiveReceiver class.

---

<div class="post-metadata">

**Author:** ![Bogdan\_Coanda](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@Bogdan\_Coanda](https://community.wowza.com/u/Bogdan_Coanda)\
**Post date:** [July 11, 2011, 7:05am UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914/11 "2011-07-11T07:05:46Z")

</div>

I tried the onPlay handler in IMediaStreamActionNotify2, same thing it blocks the stream until I finish.

About the cuepoint example, how can I do it without having the player ask me every time for a packet ?

Reiterating what I’ve been trying to say: how can I simply add my own video/audio frames to the stream from a ModuleBase class instead of letting him play whatever content the client asked for.

Simplest example: normally, a client (let’s assume for simplicity’s sake, the live.html example page is used) connects to my server asking for the ‘test.mp4’ stream. normally, the wowza server starts sending the requested content to the client, and in the mean time, calls my module’s functions on big events (onAppStart, onConnect, play, etc.) so I can gather statistics and other stuff.

What I want to do is to have the client connect exactly like he usually does, but instead of letting the wowza server give him his requested content, I want to take over and send the video/audio content myself once my module gets called on play (using something simple like addVideoData/addAudioData to the client’s stream)

---

<div class="post-metadata">

**Author:** ![Bogdan\_Coanda](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@Bogdan\_Coanda](https://community.wowza.com/u/Bogdan_Coanda)\
**Post date:** [July 13, 2011, 5:26am UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914/12 "2011-07-13T05:26:01Z")

</div>

After parsing most of the wowza api, I managed to find 2 possible solutions to my problem, but I need to know if there aren’t any problems and side effects with any of them:

#1. I managed to add my own video/audio frames on a per client basis like so:

- I have a module containing the ‘play’ function

- when ‘play’ gets called in my module, I change the requested stream name, just like in the [remap stream](https://www.wowza.com/docs/how-to-override-play-to-remap-a-stream-name) example above.

- I then publish a new stream with the changed stream name

- I sleep until the stream actually gets published

- and then I continue with invokePrevious from the ‘play’ function

basically, the following minimal code:

```auto
	
public void play(IClient client, RequestFunction function, AMFDataList params)
{		
    params.set(3, newRandomName);
				
    Thread t = new Thread(new FramePublisher(newRandomName)); 
    t.start();
    // the frame publisher creates a new publisher with the given stream name and
    // starts adding video and audio frames
		
    while(newRandomName no published yet)
        Thread.sleep();
    invokePrevious(client, function, params);
}

```

this works in my tests, but what worries me is if it’s accepted, if it doesn’t have any side effects I don’t see at the moment, and if the api’s behavior won’t change with wowza upgrades and patches as it’s not a documented, publicly accepted usage of the Publisher API.

#2. The other solution I could find, is implement my own MediaReader class, add it to the ‘MediaReaders.xml’ file, and inside my reader class I should take care of adding my own frames instead of reading them from a file, like MediaReaderH264. The problem here is that I don’t have any examples regarding the MediaReader like I had for the Publisher API.

what I need to know if I can rely on the publisher api to work like I described above (a publisher created for each client connected, and stopped at disconnect), or should I write my own MediaReader (for which I would really need an example from you guys)

---

<div class="post-metadata">

**Author:** ![Bogdan\_Coanda](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@Bogdan\_Coanda](https://community.wowza.com/u/Bogdan_Coanda)\
**Post date:** [July 13, 2011, 7:38am UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914/13 "2011-07-13T07:38:42Z")

</div>

I saw the midroll example, and it’s not helping… I don’t want to send metadata, I want to send the actual video and audio frames. For example, the publisher api specified exactly what header bytes it wanted for video/audio frames.

And you completely overlooked the other part of my above post, regarding the usage of the publisher api, as the examples I’ve seen create a publisher at the server start-up in a IServerNotify class, not at client play time in a ModuleBase class - for which I was asking if it’s intended behavior to allow me to create a publisher for each and every client coming along.

---

<div class="post-metadata">

**Author:** ![Nitin\_kaplan](https://avatars.discourse-cdn.com/v4/letter/n/ea5d25/32.png) [@Nitin\_kaplan](https://community.wowza.com/u/Nitin_kaplan)\
**Post date:** [November 19, 2012, 9:00am UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914/14 "2012-11-19T09:00:13Z")

</div>

> After parsing most of the wowza api, I managed to find 2 possible solutions to my problem, but I need to know if there aren’t any problems and side effects with any of them:
> 
> #1. I managed to add my own video/audio frames on a per client basis like so:
> 
> - I have a module containing the ‘play’ function
> 
> - when ‘play’ gets called in my module, I change the requested stream name, just like in the [remap stream](https://www.wowza.com/docs/how-to-override-play-to-remap-a-stream-name) example above.
> 
> - I then publish a new stream with the changed stream name
> 
> - I sleep until the stream actually gets published
> 
> - and then I continue with invokePrevious from the ‘play’ function
> 
> basically, the following minimal code:
> 
> ```auto
> 	
> public void play(IClient client, RequestFunction function, AMFDataList params)
> {		
> params.set(3, newRandomName);
> 				
> Thread t = new Thread(new FramePublisher(newRandomName)); 
> t.start();
> // the frame publisher creates a new publisher with the given stream name and
> // starts adding video and audio frames
> 		
> while(newRandomName no published yet)
> Thread.sleep();
> invokePrevious(client, function, params);
> }
> 
> ```
> 
> this works in my tests, but what worries me is if it’s accepted, if it doesn’t have any side effects I don’t see at the moment, and if the api’s behavior won’t change with wowza upgrades and patches as it’s not a documented, publicly accepted usage of the Publisher API.
> 
> Hi Excelle,
> 
> I am having similar problem like you did several months ago of adding few video frames before a live stream. I see that you have got it working using Publisher API. I tried doing it the way you have. But I am not sure what you have used for Publisher API? Is it the publisher class (wowza server side API doc page #1289) you are referring to? Can you give any hints as to what you have used within FramePublisher above?
> 
> I am badly stuck and this be really helpful. Thanks in advance
> 
> Rgds
> 
> Nitin

---

<div class="post-metadata">

**Author:** ![Nitin\_kaplan](https://avatars.discourse-cdn.com/v4/letter/n/ea5d25/32.png) [@Nitin\_kaplan](https://community.wowza.com/u/Nitin_kaplan)\
**Post date:** [November 21, 2012, 12:57am UTC](https://community.wowza.com/t/overriding-modulebase-streaming/36914/15 "2012-11-21T00:57:43Z")

</div>

Hi Richard,

Thanks for the quick reply. I checked out the link. Is it possible to stream out sample.mp4 only once instead of looping it?

Nitin
