Netty服务器端RTSP交错RTP(解码和处理)

时间:2016-03-02 13:59:26

标签: java netty rtsp rtp

我是netty的初学者,我需要一种方法来处理RTSP和RTP,如ED-137_4B(嵌入式交错二进制数据)规范中所述。 我目前使用netty框架版本4.0.24,但我在4.0.34等更高版本中找不到支持RTSP的嵌入式交错二进制数据,其中RTP在RTSP包中交错。 我已经尝试了很多东西,例如我试图用RTPServerInitilizer实现第二个childHandler,它应该处理RTP解码,但这与RTSP解码器不兼容。 我也试图实现两个piplines(见下文),但这也没有合作。

总结,当我将RTSP解码器和RTP解码器一起实现时,例如使用完全独立的RTSP& amp;初始化器。 RTP或我实现两个单独的管道,然后总是只有一个解码器工作。例如,如果RTSP设置在第一位,那么只有RTSP事件将被解码,如果RTP解码器在第一位,那么只有RTP包将被解码。 如果客户端断开连接,那么我可以看到其他解码器将尝试像队列一样进行解码,但是来自客户端的消息不再可用。可以通过与“NioServerSocketChannel.class”相同的TCP-Socket同步处理许多不同的RTSP客户端吗?

拜托,您能给我一个提示或者您能帮我解决一起使用RTSP和RTP的问题吗,因为我需要它来处理新工作中的项目,它是否正常?

非常感谢提前: - )

以下是我的代码段:

//***-->For your interest, functions that begin with HttpServer... handle the RTSP events!<--**//

public class HttpServerInitializer extends ChannelInitializer<SocketChannel>{    
    @Override
    public void initChannel(SocketChannel ch)  {

     //Handling of RTSP
         ChannelPipeline p = ch.pipeline();

       p.addLast(new RtspResponseEncoder());
       p.addFirst(new RtspRequestDecoder()); 

       p.addLast(new HttpObjectAggregator(65536));
       p.addLast(new HttpContentCompressor());        
       p.addLast(new ChunkedWriteHandler());       
       p.addLast(new HttpServerHandler());    


     //Second pipeline for handling of RTP
     ChannelPipeline pp = ch.pipeline();            
     pp.addLast(new RTPDecoder());
     pp.addLast(new RTPHandler());
    }
}


public class HttpServer {

    //static final int PORT = 554;
    public Channel ch = null;

    public void connect(int iPort) throws Exception {

        // Configure the server.
        EventLoopGroup bossGroup = new NioEventLoopGroup(1);
        EventLoopGroup workerGroup = new NioEventLoopGroup();
        //try {
            ServerBootstrap b = new ServerBootstrap();
            b.group(bossGroup, workerGroup)
             .channel(NioServerSocketChannel.class)
             //.childHandler(new RtpServerInitializer())    //Second separately initializer did not worked together with initializer for RTSP
             //.handler(new LoggingHandler(LogLevel.ERROR))
             .childHandler(new HttpServerInitializer());  

            ch = b.bind(iPort).sync().channel();

        /*    ch.closeFuture().sync();
        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }*/
    }   
} 


public class HttpServerHandler extends SimpleChannelInboundHandler <HttpObject> { 

    private HttpRequest m_request;
    /** Buffer that stores the response content for only log output**/
    private final StringBuilder buf = new StringBuilder();


    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg)
            throws Exception {
        // TODO Auto-generated method stub

        if (msg instanceof HttpRequest) {
            m_request = (HttpRequest) msg;
        ....
}
...
    }
  }


public class RTPDecoder extends ByteToMessageDecoder {

private ByteBuf collector = Unpooled.buffer();

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out)
        throws Exception {
…
    }
   ...
  }


public class RTPHandler extends SimpleChannelInboundHandler<ByteToMessageDecoder> { 

    @Override 
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) throws Exception { 

            super.exceptionCaught(ctx, e);            
    } 

    public void channelRead(ChannelHandlerContext ctx,  Object msg)
            throws Exception {
        // TODO Auto-generated method stub
    …
    }
 …
 }

0 个答案:

没有答案