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.sdp;
025:
026: import java.io.*;
027: import java.util.*;
028:
029: public class SessionDescription extends Parser {
030: public Vector sessionAttributes;
031: public Vector timeDescriptions;
032: public Vector mediaDescriptions;
033: public boolean connectionIncluded;
034:
035: // Values:
036: public String version;
037: public String origin;
038: public String sessionName;
039: public String sessionInfo;
040: public String uri;
041: public String email;
042: public String phone;
043: public String connectionInfo;
044: public String bandwidthInfo;
045: public String timezoneAdjustment;
046: public String encryptionKey;
047:
048: public SessionDescription(ByteArrayInputStream bin) {
049: // Protocol Version:
050: version = getLine(bin);
051:
052: connectionIncluded = false;
053:
054: timeDescriptions = new Vector();
055: sessionAttributes = new Vector();
056: mediaDescriptions = new Vector();
057:
058: String tag = getTag(bin);
059:
060: while (tag != null && tag.length() > 0) {
061: if (tag.equals("o=")) {
062: origin = getLine(bin);
063: debug("origin: " + origin);
064: } else if (tag.equals("s=")) {
065: sessionName = getLine(bin);
066: debug("session name: " + sessionName);
067: } else if (tag.equals("i=")) {
068: sessionInfo = getLine(bin);
069: debug("session info: " + sessionInfo);
070: } else if (tag.equals("u=")) {
071: uri = getLine(bin);
072: debug("uri: " + uri);
073: } else if (tag.equals("e=")) {
074: email = getLine(bin);
075: debug("email: " + email);
076: } else if (tag.equals("p=")) {
077: phone = getLine(bin);
078: debug("phone: " + phone);
079: } else if (tag.equals("c=")) {
080: connectionIncluded = true;
081:
082: connectionInfo = getLine(bin);
083: debug("connection info: " + connectionInfo);
084: } else if (tag.equals("b=")) {
085: bandwidthInfo = getLine(bin);
086: debug("bandwidth info: " + bandwidthInfo);
087: } else if (tag.equals("t=")) {
088: TimeDescription timeDescription = new TimeDescription(
089: bin);
090:
091: timeDescriptions.addElement(timeDescription);
092: } else if (tag.equals("z=")) {
093: timezoneAdjustment = getLine(bin);
094: debug("timezone adjustment: " + timezoneAdjustment);
095: } else if (tag.equals("k=")) {
096: encryptionKey = getLine(bin);
097: debug("encryption key: " + encryptionKey);
098: } else if (tag.equals("a=")) {
099: String sessionAttribute = getLine(bin);
100: debug("session attribute: " + sessionAttribute);
101:
102: int index = sessionAttribute.indexOf(':');
103:
104: if (index > 0) {
105: String name = sessionAttribute.substring(0, index);
106: String value = sessionAttribute
107: .substring(index + 1);
108:
109: MediaAttribute attribute = new MediaAttribute(name,
110: value);
111:
112: sessionAttributes.addElement(attribute);
113: }
114: } else if (tag.equals("m=")) {
115: MediaDescription mediaDescription = new MediaDescription(
116: bin, connectionIncluded);
117:
118: mediaDescriptions.addElement(mediaDescription);
119: }
120:
121: tag = getTag(bin);
122: }
123: }
124:
125: public MediaAttribute getSessionAttribute(String name) {
126: MediaAttribute attribute = null;
127:
128: if (sessionAttributes != null) {
129: for (int i = 0; i < sessionAttributes.size(); i++) {
130: MediaAttribute entry = (MediaAttribute) sessionAttributes
131: .elementAt(i);
132:
133: if (entry.getName().equals(name)) {
134: attribute = entry;
135: break;
136: }
137: }
138: }
139:
140: return attribute;
141: }
142:
143: public MediaDescription getMediaDescription(String name) {
144: MediaDescription description = null;
145:
146: if (mediaDescriptions != null) {
147: for (int i = 0; i < mediaDescriptions.size(); i++) {
148: MediaDescription entry = (MediaDescription) mediaDescriptions
149: .elementAt(i);
150:
151: if (entry.name.equals(name)) {
152: description = entry;
153: break;
154: }
155: }
156: }
157:
158: return description;
159: }
160:
161: public Vector getMediaDescriptions() {
162: return mediaDescriptions;
163: }
164: }
|