001: /*
002: * Copyright 1990-2007 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;
025:
026: import java.util.Hashtable;
027:
028: import javax.microedition.media.Player;
029:
030: /**
031: * The configuration module for MMAPI.
032: *
033: * @created January 13, 2005
034: */
035: public abstract class Configuration {
036:
037: /**
038: * A hash table of the protocol and content handlers.
039: */
040: protected Hashtable handlers;
041:
042: /**
043: * A hash table of media processors.
044: */
045: protected Hashtable processors;
046:
047: /**
048: * A table of mime types.
049: */
050: protected Hashtable mimeTypes;
051:
052: /**
053: * The current configuration object.
054: */
055: private static Configuration config;
056:
057: /**
058: * True if players loop in native code,
059: * otherwise false
060: */
061: protected static boolean nativeLooping = false;
062:
063: public final static String TONE_DEVICE_LOCATOR = "device://tone"; //javax.microedition.media.Manager.TONE_DEVICE_LOCATOR;
064: public final static String MIDI_DEVICE_LOCATOR = "device://midi"; //javax.microedition.media.Manager.MIDI_DEVICE_LOCATOR;
065: public final static String RADIO_CAPTURE_LOCATOR = "capture://radio";
066: public final static String AUDIO_CAPTURE_LOCATOR = "capture://audio";
067: public final static String VIDEO_CAPTURE_LOCATOR = "capture://video";
068:
069: protected Hashtable properties;
070:
071: private static Object singletonLock = new Object();
072:
073: /**
074: * Constructor for the Configuration object
075: */
076: public Configuration() {
077: handlers = new Hashtable();
078: processors = new Hashtable();
079: mimeTypes = new Hashtable();
080: properties = new Hashtable();
081: }
082:
083: /**
084: * Gets the supportedContentTypes attribute of the Configuration object
085: *
086: * @param protocol Description of the Parameter
087: * @return The supportedContentTypes value
088: */
089: public abstract String[] getSupportedContentTypes(String protocol);
090:
091: /**
092: * Gets the supportedProtocols attribute of the Configuration class
093: *
094: * @param content_types Description of the Parameter
095: * @return The supportedProtocols value
096: */
097: public abstract String[] getSupportedProtocols(String content_types);
098:
099: public abstract String[] getSupportedMediaProcessorInputTypes();
100:
101: public abstract String[] getSupportedSoundSource3DPlayerTypes();
102:
103: public abstract String getProperty(String key);
104:
105: public abstract void setProperty(String key, String value);
106:
107: /**
108: * Gets the audio renderer.
109: *
110: * @return The audio renderer
111: */
112: public abstract PCMAudioOut getAudioRenderer();
113:
114: /**
115: * Gets the video renderer.
116: *
117: * @return The video renderer
118: */
119: public abstract VideoRenderer getVideoRenderer(Player player,
120: int sourceWidth, int sourceHeight);
121:
122: /**
123: * Gets the tonePlayer attribute of the Configuration object
124: *
125: * @return The tonePlayer value
126: */
127: public abstract TonePlayer getTonePlayer();
128:
129: /**
130: * Convert from the name of a file to its corresponding Mime
131: * type based on the extension.
132: *
133: * @param name Description of the Parameter
134: * @return Description of the Return Value
135: */
136: public String ext2Mime(String name) {
137: int idx = name.lastIndexOf('.');
138: String ext;
139: if (idx != -1) {
140: ext = name.substring(idx + 1).toLowerCase();
141: } else {
142: ext = name.toLowerCase();
143: }
144: return (String) mimeTypes.get(ext);
145: }
146:
147: /**
148: * Gets the handler attribute of the Configuration object
149: *
150: * @param type The content type
151: * @return The handler value
152: */
153: public String getHandler(String type) {
154: return (String) handlers.get(type);
155: }
156:
157: /**
158: * Gets the processor attribute of the Configuration object
159: *
160: * @param type The content type
161: * @return The processor value
162: */
163: public String getMediaProcessor(String type) {
164: return (String) processors.get(type);
165: }
166:
167: /**
168: * Gets Accessor to platform specific Image classes
169: * To be defined in derived classes.
170: *
171: * @return instance of ImageAccess class
172: */
173: public abstract ImageAccess getImageAccessor();
174:
175: /**
176: * Gets the configuration attribute of the Configuration class
177: *
178: * @return The configuration value
179: */
180: public static Configuration getConfiguration() {
181: synchronized (singletonLock) {
182: if (config != null)
183: return config;
184:
185: String className = System
186: .getProperty("mmapi-configuration");
187:
188: if (className != null) {
189: try {
190: // ... try and instantiate the configuration class ...
191: Class handlerClass = Class.forName(className);
192: config = (Configuration) handlerClass.newInstance();
193: } catch (Exception e) {
194: // return DefaultConfiguration
195: config = new DefaultConfiguration();
196: }
197: } else {
198: config = new DefaultConfiguration();
199: }
200:
201: return config;
202: }
203: }
204:
205: /**
206: * Description of the Method
207: *
208: * @return Description of the Return Value
209: */
210: public static boolean nativeLoopMode() {
211: return nativeLooping;
212: }
213: }
|