我是一个netty的初学者,我需要一种处理RTSP和RTP的方式,就像ED-137_4B(嵌入式交错二进制数据)规范中所描述的那样。我目前使用的是netty框架版本4.0.24,但我在更高版本中(如4.0.34)找不到支持嵌入式交错二进制数据的RTSP支持,其中RTP被交错在RTSP包中。
我尝试了很多方法,例如我尝试实现一个第二个childHandler,其中包含RTPServerInitilizer,它应该处理RTP解码,但这也不能与RTSP解码器一起使用。
我还尝试了实现两个piplines(见下文),但这也不能共同使用。
总之,当我为RTSP解码器和RTP解码器同时实现完全独立的初始化程序,或者使用两个独立的管道进行实现时,只有一个解码器能够工作。例如,如果将RTSP设置在第一位,那么只有RTSP事件会被解码;如果将RTP解码器放在第一位,那么只有RTP包会被解码。如果客户端断开连接,则可以看到另一个解码器将尝试像队列一样解码,但然后客户端的消息将不再可用。是否可以使用“NioServerSocketChannel.class”同步处理许多不同的RTSP客户端?
请问,你能给我一个提示或帮助我如何解决使用RTSP和RTP的问题吗?因为我需要在新工作中使用它,这是紧急的。
非常感谢您的帮助 :-)
以下是我的代码片段:
我尝试了很多方法,例如我尝试实现一个第二个childHandler,其中包含RTPServerInitilizer,它应该处理RTP解码,但这也不能与RTSP解码器一起使用。
我还尝试了实现两个piplines(见下文),但这也不能共同使用。
总之,当我为RTSP解码器和RTP解码器同时实现完全独立的初始化程序,或者使用两个独立的管道进行实现时,只有一个解码器能够工作。例如,如果将RTSP设置在第一位,那么只有RTSP事件会被解码;如果将RTP解码器放在第一位,那么只有RTP包会被解码。如果客户端断开连接,则可以看到另一个解码器将尝试像队列一样解码,但然后客户端的消息将不再可用。是否可以使用“NioServerSocketChannel.class”同步处理许多不同的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
…
}
…
}