Example usage for io.netty.handler.codec.rtsp RtspEncoder RtspEncoder

List of usage examples for io.netty.handler.codec.rtsp RtspEncoder RtspEncoder

Introduction

In this page you can find the example usage for io.netty.handler.codec.rtsp RtspEncoder RtspEncoder.

Prototype

RtspEncoder

Source Link

Usage

From source file:sas.systems.imflux.session.rtsp.SimpleRtspSession.java

License:Apache License

/**
 * {@inheritDoc}//from   w  w  w . j  a  v  a  2 s .c o m
 */
@Override
public synchronized boolean init() {
    if (this.running.get()) {
        return true;
    }

    // create bootstrap
    Class<? extends ServerChannel> channelType;
    if (useNio) {
        this.workerGroup = new NioEventLoopGroup();
        this.bossGroup = new NioEventLoopGroup();
        channelType = NioServerSocketChannel.class;
    } else {
        this.workerGroup = new OioEventLoopGroup();
        this.bossGroup = new OioEventLoopGroup();
        channelType = OioServerSocketChannel.class;
    }

    bootstrap = new ServerBootstrap();
    bootstrap.group(this.bossGroup, this.workerGroup).option(ChannelOption.SO_SNDBUF, this.sendBufferSize)
            .option(ChannelOption.SO_RCVBUF, this.receiveBufferSize).channel(channelType)
            .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<Channel>() { // is used to initialize the ChannelPipeline
                @Override
                protected void initChannel(Channel ch) throws Exception {
                    ChannelPipeline pipeline = ch.pipeline();
                    pipeline.addLast("encoder", new RtspEncoder());
                    pipeline.addLast("decoder", new RtspDecoder());
                    pipeline.addLast("aggregator", new HttpObjectAggregator(64 * 1024));
                    pipeline.addLast("handler", new RtspHandler(SimpleRtspSession.this));
                }
            });
    // create channel
    try {
        ChannelFuture future = bootstrap.bind(this.localAddress);
        this.channel = future.sync().channel(); // wait for future to complete and retrieve channel

    } catch (Exception e) {
        LOG.error("Failed to bind RTSP channel for session with id " + this.id, e);
        this.workerGroup.shutdownGracefully();
        this.bossGroup.shutdownGracefully();

        this.workerGroup.terminationFuture().syncUninterruptibly();
        this.bossGroup.terminationFuture().syncUninterruptibly();
        return false;
    }
    LOG.debug("RTSP channel bound for RtspSession with id {}.", this.id);
    this.running.set(true);
    return true;
}

From source file:sas.systems.imflux.session.rtsp.SimpleRtspSession.java

License:Apache License

/**
 * {@inheritDoc}/*from ww  w  . jav a2 s .c  o m*/
 */
@Override
public boolean sendRequest(HttpRequest request, SocketAddress remoteAddress) {
    if (!this.running.get()) {
        return false;
    }

    // create channel and connect it to the given remote
    final Channel ch = new NioSocketChannel();
    final ChannelPipeline pipe = ch.pipeline();
    pipe.addLast("encoder", new RtspEncoder());
    pipe.addLast("decoder", new RtspDecoder());
    pipe.addLast("aggregator", new HttpObjectAggregator(64 * 1024));
    pipe.addLast("handler", new RtspHandler(SimpleRtspSession.this));
    this.workerGroup.register(ch);

    ch.connect(remoteAddress).syncUninterruptibly();

    return internalSend(request, ch);
}