001: /*
002: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License version
007: * 2 only, as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful, but
010: * WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * General Public License version 2 for more details (a copy is
013: * included at /legal/license.txt).
014: *
015: * You should have received a copy of the GNU General Public License
016: * version 2 along with this work; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018: * 02110-1301 USA
019: *
020: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021: * Clara, CA 95054 or visit www.sun.com if you need additional
022: * information or have any questions.
023: */
024: package com.sun.mmedia.rtsp.protocol;
025:
026: /**
027: * Parses the Transport Header in the RTSP response message.
028: *
029: * @author Marc Owerfeldt
030: * @created June 7, 2003
031: */
032: public class TransportHeader {
033: /**
034: * The transport protocol, i.e. RTP.
035: */
036: private String transportProtocol;
037:
038: /**
039: * The profile, i.e. AVP
040: */
041: private String profile;
042:
043: /**
044: * The lower transport layer, for example UDP.
045: */
046: private String lowerTransport;
047:
048: /**
049: * The client data port.
050: */
051: private int client_data_port;
052:
053: /**
054: * The client control port.
055: */
056: private int client_control_port;
057:
058: /**
059: * The server data port.
060: */
061: private int server_data_port;
062:
063: /**
064: * The server control port.
065: */
066: private int server_control_port;
067:
068: /**
069: * Constructor for the TransportHeader object.
070: *
071: * @param str The transport header to be parsed.
072: */
073: public TransportHeader(String str) {
074: // transport protocol:
075: int end = str.indexOf('/');
076:
077: transportProtocol = str.substring(0, end);
078:
079: // profile:
080: int start = end + 1;
081: end = str.indexOf(";", start);
082:
083: profile = str.substring(start, end);
084:
085: // lower layer transport:
086: start = end + 1;
087: end = str.indexOf(";", start);
088:
089: lowerTransport = str.substring(start, end);
090:
091: // client port:
092: start = str.indexOf("client_port");
093:
094: if (start > 0) {
095: // client data port:
096: start = str.indexOf("=", start) + 1;
097:
098: end = str.indexOf("-", start);
099:
100: String data_str = str.substring(start, end);
101:
102: client_data_port = Integer.parseInt(data_str);
103:
104: // client control port:
105: start = end + 1;
106:
107: end = str.indexOf(";", start);
108:
109: String control_str;
110:
111: if (end > 0) {
112: control_str = str.substring(start, end);
113: } else {
114: control_str = str.substring(start);
115: }
116:
117: client_control_port = Integer.parseInt(control_str);
118: }
119:
120: // server port:
121: start = str.indexOf("server_port");
122:
123: if (start > 0) {
124: // server data port:
125: start = str.indexOf("=", start) + 1;
126:
127: end = str.indexOf("-", start);
128:
129: String data_str = str.substring(start, end);
130:
131: server_data_port = Integer.parseInt(data_str);
132:
133: // server control port:
134: start = end + 1;
135:
136: end = str.indexOf(";", start);
137:
138: String control_str;
139:
140: if (end > 0) {
141: control_str = str.substring(start, end);
142: } else {
143: control_str = str.substring(start);
144: }
145:
146: server_control_port = Integer.parseInt(control_str);
147: }
148: }
149:
150: /**
151: * Gets the transport protocol
152: *
153: * @return The transport protocol
154: */
155: public String getTransportProtocol() {
156: return transportProtocol;
157: }
158:
159: /**
160: * Gets the RTP profile
161: *
162: * @return The profile
163: */
164: public String getProfile() {
165: return profile;
166: }
167:
168: /**
169: * Gets the lower layer transport protocol
170: *
171: * @return The lower layer transport protocol
172: */
173: public String getLowerTransportProtocol() {
174: return lowerTransport;
175: }
176:
177: /**
178: * Gets the server data port
179: *
180: * @return The server data port
181: */
182: public int getServerDataPort() {
183: return server_data_port;
184: }
185:
186: /**
187: * Gets the server control port
188: *
189: * @return The server control port
190: */
191: public int getServerControlPort() {
192: return server_control_port;
193: }
194: }
|