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

View File

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