Small performance improvements for RTSP

This commit is contained in:
Norman Maurer 2013-07-15 08:18:37 +02:00
parent 2f7759a264
commit cd51674070
2 changed files with 16 additions and 12 deletions

View File

@ -20,12 +20,15 @@ import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.util.CharsetUtil;
import static io.netty.handler.codec.http.HttpConstants.*;
/**
* Encodes an RTSP request represented in {@link FullHttpRequest} into
* a {@link ByteBuf}.
*/
public class RtspRequestEncoder extends RtspObjectEncoder<HttpRequest> {
private static final byte[] CRLF = { CR, LF };
@Override
public boolean acceptOutboundMessage(Object msg) throws Exception {
@ -35,12 +38,11 @@ public class RtspRequestEncoder extends RtspObjectEncoder<HttpRequest> {
@Override
protected void encodeInitialLine(ByteBuf buf, HttpRequest request)
throws Exception {
buf.writeBytes(request.getMethod().toString().getBytes(CharsetUtil.US_ASCII));
buf.writeByte((byte) ' ');
encodeAscii(request.getMethod().toString(), buf);
buf.writeByte(SP);
buf.writeBytes(request.getUri().getBytes(CharsetUtil.UTF_8));
buf.writeByte((byte) ' ');
buf.writeBytes(request.getProtocolVersion().toString().getBytes(CharsetUtil.US_ASCII));
buf.writeByte((byte) '\r');
buf.writeByte((byte) '\n');
buf.writeByte(SP);
encodeAscii(request.getProtocolVersion().toString(), buf);
buf.writeBytes(CRLF);
}
}

View File

@ -20,12 +20,15 @@ import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.util.CharsetUtil;
import static io.netty.handler.codec.http.HttpConstants.*;
/**
* Encodes an RTSP response represented in {@link FullHttpResponse} into
* a {@link ByteBuf}.
*/
public class RtspResponseEncoder extends RtspObjectEncoder<HttpResponse> {
private static final byte[] CRLF = { CR, LF };
@Override
public boolean acceptOutboundMessage(Object msg) throws Exception {
@ -35,12 +38,11 @@ public class RtspResponseEncoder extends RtspObjectEncoder<HttpResponse> {
@Override
protected void encodeInitialLine(ByteBuf buf, HttpResponse response)
throws Exception {
buf.writeBytes(response.getProtocolVersion().toString().getBytes(CharsetUtil.US_ASCII));
buf.writeByte((byte) ' ');
encodeAscii(response.getProtocolVersion().toString(), buf);
buf.writeByte(SP);
buf.writeBytes(String.valueOf(response.getStatus().code()).getBytes(CharsetUtil.US_ASCII));
buf.writeByte((byte) ' ');
buf.writeBytes(String.valueOf(response.getStatus().reasonPhrase()).getBytes(CharsetUtil.US_ASCII));
buf.writeByte((byte) '\r');
buf.writeByte((byte) '\n');
buf.writeByte(SP);
encodeAscii(String.valueOf(response.getStatus().reasonPhrase()), buf);
buf.writeBytes(CRLF);
}
}