Wowza Community

Custom dynamic Overlay images

I’ve looked at some examples and was able to work out some of what I need to do. Essentially, I need to be able to load a different overlay image for each stream, and each image may change over time on occasion. Now the first part I was able to figure out based on the ModuleTranscoderOverlayExample example code. To avoid loading the images before every frame, I do it only once in the onBeforeScaleFrame method (using a flag, then setting it to false so that it doesn’t load again). So now I’m unable to get Wowza to register a modified image mid-stream so that the name stays the same, but the contents may change, and this change in content should be apparent on the stream. The issue is that even when I set the overlay to check for updates (adding a line “overlay.setCheckForUpdates(true)” in the onBeforeScaleFrame method in the example), if I change the image being displayed doesn’t change until I restart the stream. My code is somewhat similar to this:

public void onBeforeScaleFrame(TranscoderSessionVideo sessionVideo, TranscoderStreamSourceVideo sourceVideo, long frameCount)
{
	boolean encodeSource=false;
	boolean showTime=false;
	double scalingFactor=1.0;
	synchronized(lock)
	{
		if (mainImage != null)
		{
			int sourceHeight = sessionVideo.getDecoderHeight();
			int sourceWidth = sessionVideo.getDecoderWidth();
			if(showTime)
			{
				Date dNow = new Date( );
				SimpleDateFormat ft = new SimpleDateFormat("hh:mm:ss");
				wowzaText.SetText(ft.format(dNow));
				wowzaTextShadow.SetText(ft.format(dNow));
			}
			if(encodeSource)
			{
				//put the image onto the source
				scalingFactor = 1.0;
				TranscoderVideoOverlayFrame overlay = new TranscoderVideoOverlayFrame(mainImage.GetWidth(scalingFactor),
						mainImage.GetHeight(scalingFactor), mainImage.GetBuffer(scalingFactor));
				overlay.setDstX(mainImage.GetxPos(scalingFactor));
				overlay.setDstY(mainImage.GetyPos(scalingFactor));
				sourceVideo.addOverlay(overlayIndex, overlay);
			} 
			else	
			{
				///put the image onto each destination but scaled to fit
				for(EncoderInfo encoderInfo: encoderInfoList)
				{
					if (!encoderInfo.destinationVideo.isPassThrough())
					{
						int destinationHeight = encoderInfo.destinationVideo.getFrameSizeHeight();
						scalingFactor = (double)destinationHeight/(double)sourceHeight;
						TranscoderVideoOverlayFrame overlay = new TranscoderVideoOverlayFrame(mainImage.GetWidth(scalingFactor),
								mainImage.GetHeight(scalingFactor), mainImage.GetBuffer(scalingFactor));
						overlay.setDstX(mainImage.GetxPos(scalingFactor));
						overlay.setDstY(mainImage.GetyPos(scalingFactor));
						encoderInfo.destinationVideo.addOverlay(overlayIndex,	overlay);
						//Add padding to the destination video i.e. pinch
						encoderInfo.videoPadding[0] = 0; // left
						encoderInfo.videoPadding[1] = 0; // top
						encoderInfo.videoPadding[2] = 0; // right
						encoderInfo.videoPadding[3] = (int)(((double)videoBottomPadding.getStepValue())*scalingFactor); // bottom
						encoderInfo.destinationVideo.setPadding(encoderInfo.videoPadding);
					}
				}
			}
		} 
	}
	return; 
}

Any idea of how to make this checkForUpdates work?