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 MediaDescription extends Parser {
030: // Values:
031: public String name;
032: public String port;
033: public String protocol;
034: public int payload_type;
035: public String payload;
036: public String mediaTitle;
037: public String connectionInfo;
038: public String bandwidthInfo;
039: public String encryptionKey;
040: public Vector mediaAttributes;
041:
042: public MediaDescription(ByteArrayInputStream bin,
043: boolean connectionIncluded) {
044: // Media Name and Transport Address:
045: parseMediaName(getLine(bin));
046:
047: // Connection Information:
048: boolean mandatory = true;
049:
050: if (connectionIncluded) {
051: mandatory = false;
052: }
053:
054: mediaAttributes = new Vector();
055:
056: String tag = getTag(bin);
057:
058: while (tag != null && tag.length() > 0) {
059: if (tag.equals("i=")) {
060: mediaTitle = getLine(bin);
061: debug("media title: " + mediaTitle);
062: } else if (tag.equals("c=")) {
063: connectionInfo = getLine(bin);
064: debug("connection info: " + connectionInfo);
065: } else if (tag.equals("b=")) {
066: bandwidthInfo = getLine(bin);
067: debug("bandwidth info: " + bandwidthInfo);
068: } else if (tag.equals("k=")) {
069: encryptionKey = getLine(bin);
070: debug("encryption key: " + encryptionKey);
071: } else if (tag.equals("a=")) {
072: String mediaAttribute = getLine(bin);
073:
074: int index = mediaAttribute.indexOf(':');
075:
076: if (index > 0) {
077: String name = mediaAttribute.substring(0, index);
078: String value = mediaAttribute.substring(index + 1);
079:
080: MediaAttribute attribute = new MediaAttribute(name,
081: value);
082:
083: mediaAttributes.addElement(attribute);
084: }
085: } else if (tag.equals("m=")) {
086: ungetTag(tag);
087: return;
088: }
089:
090: tag = getTag(bin);
091: }
092: }
093:
094: private void parseMediaName(String line) {
095: debug("media name: " + line);
096:
097: int end = line.indexOf(' ');
098:
099: name = line.substring(0, end);
100:
101: int start = end + 1;
102:
103: end = line.indexOf(' ', start);
104:
105: port = line.substring(start, end);
106:
107: start = end + 1;
108:
109: end = line.indexOf(' ', start);
110:
111: protocol = line.substring(start, end);
112:
113: start = end + 1;
114:
115: payload = line.substring(start);
116:
117: try {
118: payload_type = Integer.parseInt(payload);
119: } catch (Exception e) {
120: payload_type = -1;
121: }
122: }
123:
124: public MediaAttribute getMediaAttribute(String name) {
125: MediaAttribute attribute = null;
126:
127: if (mediaAttributes != null) {
128: for (int i = 0; i < mediaAttributes.size(); i++) {
129: MediaAttribute entry = (MediaAttribute) mediaAttributes
130: .elementAt(i);
131:
132: if (entry.getName().equals(name)) {
133: attribute = entry;
134: break;
135: }
136: }
137: }
138:
139: return attribute;
140: }
141: }
|