Initial RTSP implementation which extended HTTP

This commit is contained in:
Trustin Lee 2010-01-25 04:26:05 +00:00
parent 1c2796983e
commit 129a54446c
6 changed files with 500 additions and 0 deletions

View File

@ -0,0 +1,93 @@
/*
* Copyright 2010 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package org.jboss.netty.handler.codec.rtsp;
import org.jboss.netty.handler.codec.http.HttpHeaders;
/**
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Amit Bhayani (amit.bhayani@gmail.com)
* @author Trustin Lee (trustin@gmail.com)
* @version $Rev$, $Date$
*/
public class RtspHeaders {
public static final class Names extends HttpHeaders.Names {
public static final String ALLOW = "Allow";
public static final String BANDWIDTH = "Bandwidth";
public static final String BLOCKSIZE = "Blocksize";
public static final String CONFERENCE = "Conference";
public static final String CSEQ = "CSeq";
public static final String PROXY_REQUIRE = "Proxy-Require";
public static final String PUBLIC = "Public";
public static final String REQUIRE = "Require";
public static final String RTP_INFO = "RTP-Info";
public static final String SCALE = "Scale";
public static final String SPEED = "Speed";
public static final String SESSION = "Session";
public static final String TIMESTAMP = "Timestamp";
public static final String TRANSPORT = "Transport";
public static final String UNSUPPORTED = "Unsupported";
protected Names() {
super();
}
}
public static class Values extends HttpHeaders.Values {
public static final String APPEND = "append";
public static final String AVP = "AVP";
public static final String CLIENT_PORT = "client_port";
public static final String DESTINATION = "destination";
public static final String INTERLEAVED = "interleaved";
public static final String LAYERS = "layers";
public static final String MODE = "mode";
public static final String MULTICAST = "multicast";
public static final String PORT = "port";
public static final String RTP = "RTP";
public static final String RTPTIME = "rtptime";
public static final String SEQ = "seq";
public static final String SERVER_PORT = "server_port";
public static final String SSRC = "ssrc";
public static final String TCP = "TCP";
public static final String TIMEOUT = "timeout";
public static final String TTL = "ttl";
public static final String UDP = "UDP";
public static final String UNICAST = "unicast";
public static final String URL = "url";
protected Values() {
super();
}
}
}

View File

@ -0,0 +1,96 @@
/*
* Copyright 2010 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package org.jboss.netty.handler.codec.rtsp;
import java.util.HashMap;
import java.util.Map;
import org.jboss.netty.handler.codec.http.HttpMethod;
/**
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Amit Bhayani (amit.bhayani@gmail.com)
* @author Trustin Lee (trustin@gmail.com)
* @version $Rev$, $Date$
*/
public class RtspMethod extends HttpMethod {
public static final RtspMethod DESCRIBE = new RtspMethod("DESCRIBE");
public static final RtspMethod ANNOUNCE = new RtspMethod("ANNOUNCE");
public static final RtspMethod GET_PARAMETER = new RtspMethod(
"GET_PARAMETER");
public static final RtspMethod OPTIONS = new RtspMethod("OPTIONS");
public static final RtspMethod PAUSE = new RtspMethod("PAUSE");
public static final RtspMethod PLAY = new RtspMethod("PLAY");
public static final RtspMethod RECORD = new RtspMethod("RECORD");
public static final RtspMethod REDIRECT = new RtspMethod("REDIRECT");
public static final RtspMethod SETUP = new RtspMethod("SETUP");
public static final RtspMethod SET_PARAMETER = new RtspMethod(
"SET_PARAMETER");
public static final RtspMethod TEARDOWN = new RtspMethod("TEARDOWN");
private static final Map<String, RtspMethod> methodMap = new HashMap<String, RtspMethod>();
static {
methodMap.put(DESCRIBE.toString(), DESCRIBE);
methodMap.put(ANNOUNCE.toString(), ANNOUNCE);
methodMap.put(GET_PARAMETER.toString(), GET_PARAMETER);
methodMap.put(OPTIONS.toString(), OPTIONS);
methodMap.put(PAUSE.toString(), PAUSE);
methodMap.put(PLAY.toString(), PLAY);
methodMap.put(RECORD.toString(), RECORD);
methodMap.put(REDIRECT.toString(), REDIRECT);
methodMap.put(SETUP.toString(), SETUP);
methodMap.put(SET_PARAMETER.toString(), SET_PARAMETER);
methodMap.put(TEARDOWN.toString(), TEARDOWN);
}
public RtspMethod(String name) {
super(name);
}
public static RtspMethod valueOf(String name) {
if (name == null) {
throw new NullPointerException("name");
}
name = name.trim().toUpperCase();
if (name.length() == 0) {
throw new IllegalArgumentException("empty name");
}
RtspMethod result = methodMap.get(name);
if (result != null) {
return result;
} else {
return new RtspMethod(name);
}
}
}

View File

@ -0,0 +1,51 @@
/*
* Copyright 2010 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package org.jboss.netty.handler.codec.rtsp;
import org.jboss.netty.handler.codec.http.DefaultHttpRequest;
import org.jboss.netty.handler.codec.http.HttpMessage;
import org.jboss.netty.handler.codec.http.HttpMessageDecoder;
/**
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Amit Bhayani (amit.bhayani@gmail.com)
* @author Trustin Lee (trustin@gmail.com)
* @version $Rev$, $Date$
*/
public class RtspRequestDecoder extends HttpMessageDecoder {
public RtspRequestDecoder() {
super();
}
public RtspRequestDecoder(int maxInitialLineLength, int maxHeaderSize,
int maxChunkSize) {
super(maxInitialLineLength, maxHeaderSize, maxChunkSize);
}
@Override
protected HttpMessage createMessage(String[] initialLine) throws Exception {
return new DefaultHttpRequest(RtspVersion.valueOf(initialLine[2]),
RtspMethod.valueOf(initialLine[0]), initialLine[1]);
}
@Override
protected boolean isDecodingRequest() {
return true;
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2010 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package org.jboss.netty.handler.codec.rtsp;
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
import org.jboss.netty.handler.codec.http.HttpMessage;
import org.jboss.netty.handler.codec.http.HttpMessageDecoder;
/**
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Amit Bhayani (amit.bhayani@gmail.com)
* @author Trustin Lee (trustin@gmail.com)
* @version $Rev$, $Date$
*/
public class RtspResponseDecoder extends HttpMessageDecoder {
public RtspResponseDecoder() {
super();
}
public RtspResponseDecoder(int maxInitialLineLength, int maxHeaderSize,
int maxChunkSize) {
super(maxInitialLineLength, maxHeaderSize, maxChunkSize);
}
@Override
protected HttpMessage createMessage(String[] initialLine) throws Exception {
return new DefaultHttpResponse(RtspVersion.valueOf(initialLine[0]),
new RtspResponseStatus(Integer.valueOf(initialLine[1]),
initialLine[2]));
}
@Override
protected boolean isDecodingRequest() {
return false;
}
}

View File

@ -0,0 +1,157 @@
/*
* Copyright 2010 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package org.jboss.netty.handler.codec.rtsp;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
/**
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Amit Bhayani (amit.bhayani@gmail.com)
* @author Trustin Lee (trustin@gmail.com)
* @version $Rev$, $Date$
*/
public class RtspResponseStatus extends HttpResponseStatus {
/**
* 250 Low on Storage Space
*/
public static final RtspResponseStatus LOW_STORAGE_SPACE = new RtspResponseStatus(
250, "Low on Storage Space");
/**
* 302 Moved Temporarily
*/
public static final RtspResponseStatus MOVED_TEMPORARILY = new RtspResponseStatus(
302, "Moved Temporarily");
/**
* 451 Parameter Not Understood
*/
public static final RtspResponseStatus PARAMETER_NOT_UNDERSTOOD = new RtspResponseStatus(
451, "Parameter Not Understood");
/**
* 452 Conference Not Found
*/
public static final RtspResponseStatus CONFERENCE_NOT_FOUND = new RtspResponseStatus(
452, "Conference Not Found");
/**
* 453 Not Enough Bandwidth
*/
public static final RtspResponseStatus NOT_ENOUGH_BANDWIDTH = new RtspResponseStatus(
453, "Not Enough Bandwidth");
/**
* 454 Session Not Found
*/
public static final RtspResponseStatus SESSION_NOT_FOUND = new RtspResponseStatus(
454, "Session Not Found");
/**
* 455 Method Not Valid in This State
*/
public static final RtspResponseStatus METHOD_NOT_VALID = new RtspResponseStatus(
455, "Method Not Valid in This State");
/**
* 456 Header Field Not Valid for Resource
*/
public static final RtspResponseStatus HEADER_FIELD_NOT_VALID = new RtspResponseStatus(
456, "Header Field Not Valid for Resource");
/**
* 457 Invalid Range
*/
public static final RtspResponseStatus INVALID_RANGE = new RtspResponseStatus(
457, "Invalid Range");
/**
* 458 Parameter Is Read-Only
*/
public static final RtspResponseStatus PARAMETER_IS_READONLY = new RtspResponseStatus(
458, "Parameter Is Read-Only");
/**
* 459 Aggregate operation not allowed
*/
public static final RtspResponseStatus AGGREGATE_OPERATION_NOT_ALLOWED = new RtspResponseStatus(
459, "Aggregate operation not allowed");
/**
* 460 Only Aggregate operation allowed
*/
public static final RtspResponseStatus ONLY_AGGREGATE_OPERATION_ALLOWED = new RtspResponseStatus(
460, "Only Aggregate operation allowed");
/**
* 461 Unsupported transport
*/
public static final RtspResponseStatus UNSUPPORTED_TRANSPORT = new RtspResponseStatus(
461, "Unsupported transport");
/**
* 462 Destination unreachable
*/
public static final RtspResponseStatus DESTINATION_UNREACHABLE = new RtspResponseStatus(
462, "Destination unreachable");
/**
* 463 Destination unreachable
*/
public static final RtspResponseStatus KEY_MANAGEMENT_FAILURE = new RtspResponseStatus(
463, "Key management failure");
/**
* 505 RTSP Version not supported
*/
public static final RtspResponseStatus RTSP_VERSION_NOT_SUPPORTED = new RtspResponseStatus(
505, "RTSP Version not supported");
/**
* 551 Option not supported
*/
public static final RtspResponseStatus OPTION_NOT_SUPPORTED = new RtspResponseStatus(
551, "Option not supported");
public static HttpResponseStatus valueOf(int code) {
switch (code) {
case 250: return LOW_STORAGE_SPACE;
case 302: return MOVED_TEMPORARILY;
case 451: return PARAMETER_NOT_UNDERSTOOD;
case 452: return CONFERENCE_NOT_FOUND;
case 453: return NOT_ENOUGH_BANDWIDTH;
case 454: return SESSION_NOT_FOUND;
case 455: return METHOD_NOT_VALID;
case 456: return HEADER_FIELD_NOT_VALID;
case 457: return INVALID_RANGE;
case 458: return PARAMETER_IS_READONLY;
case 459: return AGGREGATE_OPERATION_NOT_ALLOWED;
case 460: return ONLY_AGGREGATE_OPERATION_ALLOWED;
case 461: return UNSUPPORTED_TRANSPORT;
case 462: return DESTINATION_UNREACHABLE;
case 463: return KEY_MANAGEMENT_FAILURE;
case 505: return RTSP_VERSION_NOT_SUPPORTED;
case 551: return OPTION_NOT_SUPPORTED;
default: return HttpResponseStatus.valueOf(code);
}
}
public RtspResponseStatus(int code, String reasonPhrase) {
super(code, reasonPhrase);
}
}

View File

@ -0,0 +1,51 @@
/*
* Copyright 2010 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package org.jboss.netty.handler.codec.rtsp;
import org.jboss.netty.handler.codec.http.HttpVersion;
/**
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Amit Bhayani (amit.bhayani@gmail.com)
* @author Trustin Lee (trustin@gmail.com)
* @version $Rev$, $Date$
*/
public class RtspVersion extends HttpVersion {
public static final RtspVersion RTSP_1_0 = new RtspVersion("RTSP", 1, 0);
public RtspVersion(String text) {
super(text);
}
public RtspVersion(String protocolName, int majorVersion, int minorVersion) {
super(protocolName, majorVersion, minorVersion);
}
public static RtspVersion valueOf(String text) {
if (text == null) {
throw new NullPointerException("text");
}
text = text.trim().toUpperCase();
if (text.equals("RTSP/1.0")) {
return RTSP_1_0;
}
return new RtspVersion(text);
}
}