• How to intercept and block incoming UDP packets for an RTP or MPEG-TS stream

    Sample code that shows how to intercept the incoming UDP packets of an RTP or MPEG-TS stream and control which packets are passed to the depacketizer.
    package com.wowza.wms.plugin.test;
    
    import java.io.*;
    import java.net.*;
    
    import com.wowza.wms.application.*;
    import com.wowza.wms.rtp.depacketizer.*;
    import com.wowza.wms.rtp.model.*;
    
    public class RTPDePacketizerWrapperUDPFilter implements IRTPDePacketizerWrapper
    {
    	private IRTPDePacketizer rtpDePacketizer = null;
    	private File outFile = null;
    	private RandomAccessFile fileWriter = null;
    	private Object lock = new Object();
    	private long startTime = -1;
    
    	public void handleRTCPPacket(SocketAddress socketAddr, RTPTrack rtpTrack, byte[] bytes, int offset, int len)
    	{
    		boolean isPacketOK = true;
    		
    		// determine here if RTCP packet is OK
    		
    		if (isPacketOK)
    			this.rtpDePacketizer.handleRTCPPacket(socketAddr, rtpTrack, bytes, offset, len);
    	}
    
    	public void handleRTPPacket(SocketAddress socketAddr, RTPTrack rtpTrack, byte[] bytes, int offset, int len)
    	{
    		boolean isPacketOK = true;
    		
    		// determine here if RTP packet is OK
    
    		if (isPacketOK)
    			this.rtpDePacketizer.handleRTPPacket(socketAddr, rtpTrack, bytes, offset, len);
    	}
    
    	public WMSProperties getProperties()
    	{
    		return rtpDePacketizer.getProperties();
    	}
    
    	public boolean canHandle(RTPTrack rtpTrack)
    	{
    		return this.rtpDePacketizer.canHandle(rtpTrack);
    	}
    
    	public void init(RTPContext rtpContext, RTPDePacketizerItem rtpDePacketizerItem)
    	{
    		this.rtpDePacketizer.init(rtpContext, rtpDePacketizerItem);
    	}
    
    	public void setProperties(WMSProperties properties)
    	{
    		this.rtpDePacketizer.setProperties(properties);
    	}
    
    	public void shutdown(RTPTrack rtpTrack)
    	{
    		this.rtpDePacketizer.shutdown(rtpTrack);
    	}
    
    	public void startup(RTPTrack rtpTrack)
    	{
    		this.rtpDePacketizer.startup(rtpTrack);
    	}
    
    	public void setDePacketizer(IRTPDePacketizer rtpDePacketizer)
    	{
    		this.rtpDePacketizer = rtpDePacketizer;
    	}
    	public RTPReceiverReportHandler getReceiverReportHandler()
    	{
    		return rtpDePacketizer.getReceiverReportHandler();
    	}
    }
    To add the above wrapper to your Application.xml file, add the following property to the <RTP/Properties container:
    <Property>
    	<Name>rtpDePacketizerWrapper</Name>
    	<Value>com.wowza.wms.plugin.test.RTPDePacketizerWrapperUDPFilter</Value>
    </Property>