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: import java.util.Vector;
028: import java.util.Enumeration;
029:
030: import javax.microedition.media.Player;
031:
032: /**
033: * The default configuration module for MIDP.
034: *
035: * @created January 13, 2005
036: */
037: public class DefaultConfiguration extends Configuration {
038: /**
039: * Tone sequence mime type.
040: */
041: public final static String MIME_AUDIO_TONE = "audio/x-tone-seq";
042:
043: /**
044: * AMR NB mime type.
045: */
046: public final static String MIME_AUDIO_AMR = "audio/amr";
047:
048: /**
049: * GIF mime type.
050: */
051: public final static String MIME_IMAGE_GIF = "image/gif";
052:
053: /**
054: * PNG mime type.
055: */
056: public final static String MIME_IMAGE_PNG = "image/png";
057:
058: /**
059: * JPEG mime type.
060: */
061: public final static String MIME_IMAGE_JPEG = "image/jpeg";
062:
063: /**
064: * Raw image mime type.
065: */
066: public final static String MIME_IMAGE_RAW = "image/raw";
067:
068: /**
069: * AMR WB mime type.
070: */
071: public final static String MIME_AUDIO_AMR_WB = "audio/amr-wb";
072:
073: /**
074: * WAV mime type.
075: */
076: public static final String MIME_AUDIO_WAV = "audio/x-wav";
077:
078: /**
079: * MIDI mime type.
080: */
081: public static final String MIME_AUDIO_MIDI = "audio/midi";
082:
083: /**
084: * SP-MIDI mime type.
085: */
086: public static final String MIME_AUDIO_SP_MIDI = "audio/sp-midi";
087:
088: /**
089: * MPEG mime type.
090: */
091: public static final String MIME_VIDEO_MPEG = "video/mpeg";
092:
093: /**
094: * MPEG4 mime type.
095: */
096: public final static String MIME_VIDEO_MPEG4 = "video/mpeg4";
097:
098: /**
099: * PCMU mime type.
100: */
101: public static final String MIME_AUDIO_PCMU = "audio/x-pcmu";
102:
103: /**
104: * RGB 565, Sun specific type.
105: */
106: public static final String RGB565 = "video/vnd.sun.rgb565";
107:
108: /**
109: * Handle for the Image Access Environment...
110: */
111: private static ImageAccess imageAccessor;
112:
113: /**
114: * Handle for the Tone Player...
115: */
116: private static TonePlayer myTonePlayer;
117:
118: /**
119: * defines whether to process jsr234-specific operations or not
120: * (jsr135 only).
121: */
122: private boolean needAMMS;
123:
124: /**
125: * defines which audio subsystem to use - MAP or QSound.
126: */
127: private boolean needQSound;
128:
129: protected Hashtable supportedProtocols;
130: private Hashtable supportedContentTypes;
131:
132: private Vector nullContentTypes;
133: private Vector captureContentTypes;
134: private Vector deviceContentTypes;
135: private Vector fileContentTypes;
136: private Vector httpContentTypes;
137:
138: /**
139: * Constructor for the DefaultConfiguration object
140: */
141: public DefaultConfiguration() {
142: super ();
143: supportedProtocols = new Hashtable();
144:
145: init();
146:
147: nullContentTypes = new Vector(9);
148: captureContentTypes = new Vector(2);
149: deviceContentTypes = new Vector(2);
150: fileContentTypes = new Vector(8);
151: httpContentTypes = new Vector(8);
152:
153: supportedContentTypes = new Hashtable();
154:
155: supportedContentTypes.put("capture", captureContentTypes);
156: supportedContentTypes.put("device", deviceContentTypes);
157: supportedContentTypes.put("file", fileContentTypes);
158: supportedContentTypes.put("http", httpContentTypes);
159:
160: for (Enumeration keys = supportedProtocols.keys(); keys
161: .hasMoreElements();) {
162: // one of supported mime-types, added during init()
163: String mime = (String) keys.nextElement();
164: // array of supported protocols for this mime-type
165: // can be a combination of {"capture", "device", "file", "http"}
166: String values[] = (String[]) supportedProtocols.get(mime);
167: for (int i = 0; i < values.length; ++i) {
168: //values[i] is one of {"capture", "device", "file", "http"}
169: Vector vectorContentTypes = (Vector) supportedContentTypes
170: .get(values[i]);
171: //vectorContentTypes is one of:
172: //{captureContentTypes, deviceContentTypes, fileContentTypes, httpContentTypes}
173: //TBD: add "if (vectorContentTypes != null)" to support removal of "file://" URLs
174: vectorContentTypes.addElement(mime);
175: }
176: //this one is a merge of all other *ContentTypes
177: nullContentTypes.addElement(mime);
178: }
179: /*
180: System.out.println("DEBUG: Supported properties: " + properties.toString());
181: System.out.println("DEBUG: Supported handlers: " + handlers.toString());
182: System.out.println("DEBUG: Supported processors: " + processors.toString());
183:
184: System.out.println("DEBUG: Supported mime-types: " + mimeTypes.toString());
185: System.out.println("DEBUG: Supported content-types: " + supportedContentTypes.toString());
186: System.out.println("DEBUG: Supported protocols: " + supportedProtocols.toString());
187:
188: System.out.println("DEBUG: null content-types: " + nullContentTypes.toString());
189: System.out.println("DEBUG: capture content-types: " + captureContentTypes.toString());
190: System.out.println("DEBUG: device content-types: " + deviceContentTypes.toString());
191: System.out.println("DEBUG: file content-types: " + fileContentTypes.toString());
192: System.out.println("DEBUG: http content-types: " + httpContentTypes.toString());
193: */
194: }
195:
196: /**
197: * method that performs real initialization.
198: * Called only from constructor.
199: * Must be overwritted by derived classes
200: */
201: protected void init() {
202: System.err
203: .println("Failed to find configuration object - DefaultConfiguration is used!");
204:
205: try {
206: String value = System
207: .getProperty("microedition.amms.version");
208: needAMMS = (value != null);
209: } catch (Exception e) {
210: needAMMS = false;
211: }
212: try {
213: String value = System
214: .getProperty("supports.mediacapabilities");
215: needQSound = (value.indexOf("audio3d") != -1);
216: } catch (Exception e) {
217: needQSound = false;
218: }
219:
220: // Protocol handlers.
221: handlers.put("http", "com.sun.mmedia.protocol.CommonDS");
222: handlers.put("file", "com.sun.mmedia.protocol.CommonDS");
223: handlers.put("capture", "com.sun.mmedia.protocol.WavCapture");
224:
225: // Device handlers.
226: if (needQSound) {
227: handlers.put(TONE_DEVICE_LOCATOR,
228: "com.sun.mmedia.QSoundToneSequencePlayer");
229: handlers.put(MIDI_DEVICE_LOCATOR,
230: "com.sun.mmedia.QSoundMIDIPlayer");
231: } else {
232: handlers.put(TONE_DEVICE_LOCATOR,
233: "com.sun.mmedia.ToneSequencePlayer");
234: handlers.put(MIDI_DEVICE_LOCATOR,
235: "com.sun.mmedia.MIDIPlayer");
236: }
237:
238: if (needAMMS) {
239: handlers.put(RADIO_CAPTURE_LOCATOR,
240: "com.sun.amms.AmmsTuner");
241: handlers.put(VIDEO_CAPTURE_LOCATOR,
242: "com.sun.amms.AmmsCameraPlayer");
243: } else {
244: handlers.put(RADIO_CAPTURE_LOCATOR,
245: "com.sun.mmedia.MmapiTuner");
246: handlers.put(VIDEO_CAPTURE_LOCATOR,
247: "com.sun.mmedia.MmapiCameraPlayer");
248: }
249:
250: // Content handlers.
251:
252: // RGB565 content ... - internal image capture format
253: supportedProtocols.put(RGB565, cProtocols);
254:
255: // AMR content ... - disabled, can't determine implementation to use
256: /*
257: // this one is licensed full functional AMR player
258: //handlers.put(MIME_AUDIO_AMR, "com.sun.mmedia.AMRPlayer");
259: //handlers.put(MIME_AUDIO_AMR_WB, "com.sun.mmedia.AMRPlayer");
260: *
261: //this one is emulation player provided by Toolkit+QuickTime
262: //handlers.put(MIME_AUDIO_AMR, "com.sun.mmedia.AMR3DConnectablePlayer2");
263: //QuickTime doesn't support amr-wb: handlers.put(MIME_AUDIO_AMR_WB, "");
264: *
265: //supportedProtocols.put(MIME_AUDIO_AMR, hfProtocols);
266: ////TO PASS MMAPI-TCK 1.1: supportedProtocols.put(MIME_AUDIO_AMR_WB, hfProtocols);
267: */
268: // MIDI/Tone Sequence content ...
269: if (needQSound) {
270: handlers.put(MIME_AUDIO_TONE,
271: "com.sun.mmedia.QSoundToneSequencePlayer");
272: handlers.put(MIME_AUDIO_MIDI,
273: "com.sun.mmedia.QSoundMIDIPlayer");
274: handlers.put(MIME_AUDIO_SP_MIDI,
275: "com.sun.mmedia.QSoundMIDIPlayer");
276: } else {
277: handlers.put(MIME_AUDIO_TONE,
278: "com.sun.mmedia.ToneSequencePlayer");
279: handlers.put(MIME_AUDIO_MIDI, "com.sun.mmedia.MIDIPlayer");
280: handlers.put(MIME_AUDIO_SP_MIDI,
281: "com.sun.mmedia.MIDIPlayer");
282: }
283: supportedProtocols.put(MIME_AUDIO_TONE, hfdProtocols);
284: supportedProtocols.put(MIME_AUDIO_MIDI, hfdProtocols);
285: supportedProtocols.put(MIME_AUDIO_SP_MIDI, hfProtocols);
286:
287: // Other multimedia content ...
288: handlers.put(MIME_IMAGE_GIF, "com.sun.mmedia.GIFPlayer");
289: handlers.put(MIME_AUDIO_WAV, "com.sun.mmedia.WavPlayer");
290: handlers
291: .put(MIME_VIDEO_MPEG, "com.sun.mmedia.JavaMPEG1Player2");
292:
293: supportedProtocols.put(MIME_IMAGE_GIF, hfProtocols);
294: supportedProtocols.put(MIME_AUDIO_WAV, hfcProtocols);
295: supportedProtocols.put(MIME_VIDEO_MPEG, hfProtocols);
296:
297: if (needAMMS) {
298: // Media Processors.
299: processors.put(MIME_IMAGE_RAW,
300: "com.sun.amms.RAWImageProcessor");
301: processors.put(MIME_IMAGE_JPEG,
302: "com.sun.amms.JPEGImageProcessor");
303: processors.put(MIME_IMAGE_PNG,
304: "com.sun.amms.PNGImageProcessor");
305: }
306:
307: // define MIDI Tone Player class
308: if (needQSound) {
309: setProperty("com.sun.mmedia.TonePlayer",
310: "com.sun.mmedia.QSoundTonePlayer");
311: } else {
312: setProperty("com.sun.mmedia.TonePlayer",
313: "com.sun.mmedia.MIDIOut");
314: }
315:
316: // define audio renderer class
317: if (needQSound) {
318: setProperty("com.sun.mmedia.PCMAudioOut",
319: "com.sun.mmedia.QSoundPCMOut");
320: } else {
321: setProperty("com.sun.mmedia.PCMAudioOut",
322: "com.sun.mmedia.MapPCMOut");
323: }
324:
325: if (needAMMS) {
326: // define class that implement AMMS GlobalManager object
327: if (needQSound)
328: setProperty("javax.microedition.amms.GlobalManager",
329: "com.sun.mmedia.QSoundGlobalManager");
330: else
331: setProperty("javax.microedition.amms.GlobalManager",
332: "com.sun.mmedia.MapGlobalManager");
333: }
334:
335: // Mime types
336: mimeTypes.put("jts", MIME_AUDIO_TONE);
337: mimeTypes.put("amr", MIME_AUDIO_AMR);
338: mimeTypes.put("awb", MIME_AUDIO_AMR_WB);
339: mimeTypes.put("gif", MIME_IMAGE_GIF);
340: mimeTypes.put("wav", MIME_AUDIO_WAV);
341: mimeTypes.put("mpg", MIME_VIDEO_MPEG);
342: mimeTypes.put("mpeg", MIME_VIDEO_MPEG);
343: mimeTypes.put("mid", MIME_AUDIO_MIDI);
344: mimeTypes.put("midi", MIME_AUDIO_SP_MIDI);
345:
346: // for converting
347: mimeTypes.put("audio/tone", MIME_AUDIO_TONE);
348: mimeTypes.put("audio/wav", MIME_AUDIO_WAV);
349: mimeTypes.put("audio/x-wav", MIME_AUDIO_WAV); // do we need this duplication ?
350: mimeTypes.put("audio/x-midi", MIME_AUDIO_MIDI);
351: mimeTypes.put("audio/amr", MIME_AUDIO_AMR); // do we need this duplication ?
352: mimeTypes.put("audio/amr-wb", MIME_AUDIO_AMR_WB); // do we need this duplication ?
353: mimeTypes.put("audio/sp-midi", MIME_AUDIO_SP_MIDI); // do we need this duplication ?
354: mimeTypes.put("audio/x-pcmu", MIME_AUDIO_PCMU); // do we need this duplication ?
355: mimeTypes.put("video/x-jpeg", MIME_IMAGE_JPEG);
356:
357: initTunerProperties();
358:
359: /**
360: * will return NULL until issue with "classByName" creatio
361: * of MIDPImageAccessor will be fixed.
362: * MIDPImageAccessor will be returneed by derived classes ...
363: */
364: // Create ImageAccessor ("ImageRenderer")
365: //imageAccessor = new MIDPImageAccessor();
366: imageAccessor = null;
367:
368: // Create a Tone Player...
369: myTonePlayer = (TonePlayer) createInstanceOf("com.sun.mmedia.TonePlayer");
370: }
371:
372: /**
373: * sets group of tuner properties.
374: * Depending on real config, propery values may have different prefixes.
375: *
376: * Should not be overwritten by derived classes
377: */
378: protected void initTunerProperties() {
379: // define Tuner radio channel emulation data
380: setProperty("com.sun.tuner.presets", "5"); // number of presets (same array for FM & AM)
381: setProperty("com.sun.tuner.play", "2"); // default preset to play on startup
382:
383: setProperty("com.sun.tuner.fm.stations", "3"); //number of FM stations
384:
385: setProperty("com.sun.tuner.fm.station_1", "885000");
386: setProperty("com.sun.tuner.fm.name_1", "KCQW");
387: setProperty("com.sun.tuner.fm.text_1", "Hour of Opera");
388: setProperty("com.sun.tuner.fm.url_1", "tuner1.wav");
389: //setProperty("com.sun.tuner.fm.preset_1", "4");
390:
391: setProperty("com.sun.tuner.fm.station_2", "932000");
392: setProperty("com.sun.tuner.fm.name_2", "Rock 932");
393: setProperty("com.sun.tuner.fm.text_2", "Drive Rock");
394: setProperty("com.sun.tuner.fm.url_2", "tuner2.wav");
395: setProperty("com.sun.tuner.fm.preset_2", "3");
396:
397: setProperty("com.sun.tuner.fm.station_3", "1015000");
398: setProperty("com.sun.tuner.fm.name_3", "NNNERD");
399: setProperty("com.sun.tuner.fm.text_3", "Module Prime");
400: setProperty("com.sun.tuner.fm.url_3", "tuner4.wav");
401: setProperty("com.sun.tuner.fm.preset_3", "2");
402:
403: setProperty("com.sun.tuner.am.stations", "2"); //number of AM stations
404:
405: setProperty("com.sun.tuner.am.station_1", "5800");
406: setProperty("com.sun.tuner.am.name_1", "FUNR");
407: setProperty("com.sun.tuner.am.text_1", "Funny News");
408: setProperty("com.sun.tuner.am.url_1", "tuner3.wav");
409: setProperty("com.sun.tuner.am.preset_1", "4");
410:
411: setProperty("com.sun.tuner.am.station_2", "12110");
412: setProperty("com.sun.tuner.am.name_2", "TLKB");
413: setProperty("com.sun.tuner.am.text_2", "Talk Back");
414: setProperty("com.sun.tuner.am.url_2", "tuner5.wav");
415: setProperty("com.sun.tuner.am.preset_2", "1");
416: }
417:
418: /**
419: * Gets the supportedContentTypes attribute of the DefaultConfiguration object
420: *
421: * @param protocol Description of the Parameter
422: * @return The supportedContentTypes value
423: */
424: public String[] getSupportedContentTypes(String protocol) {
425: Vector vectorContentTypes = (protocol == null) ? (Vector) nullContentTypes
426: : (Vector) supportedContentTypes.get(protocol);
427:
428: if (vectorContentTypes == null) {
429: return new String[0];
430: } else {
431: String[] array = new String[vectorContentTypes.size()];
432: vectorContentTypes.copyInto(array);
433: return array;
434: }
435: }
436:
437: protected final static String hfdcProtocols[] = { "http", "file",
438: "device", "capture" };
439:
440: protected final static String hfcProtocols[] = { "http", "file",
441: "capture" };
442:
443: protected final static String hfdProtocols[] = { "http", "file",
444: "device" };
445:
446: protected final static String hfProtocols[] = { "http", "file" };
447:
448: protected final static String cProtocols[] = { "capture" };
449:
450: protected final static String dProtocols[] = { "device" };
451:
452: /*
453: * Shall be used if "file://" is not available:
454: *
455: protected final static String hdcProtocols[] = { "http", "device", "capture" };
456:
457: protected final static String hcProtocols[] = { "http", "capture" };
458:
459: protected final static String hdProtocols[] = { "http", "device" };
460:
461: protected final static String hProtocols[] = { "http" };
462: */
463: /**
464: * Gets the supportedProtocols attribute of the DefaultConfiguration object
465: *
466: * @param content_type Description of the Parameter
467: * @return The supportedProtocols value
468: */
469: public String[] getSupportedProtocols(String content_type) {
470: String[] array = (content_type == null) ? hfdcProtocols
471: : (String[]) supportedProtocols.get(content_type);
472: return (array == null) ? new String[0] : array;
473: }
474:
475: /**
476: * Gets the audio renderer.
477: *
478: * @return The audio renderer
479: */
480: public PCMAudioOut getAudioRenderer() {
481: return (PCMAudioOut) createInstanceOf("com.sun.mmedia.PCMAudioOut");
482: }
483:
484: /**
485: * Gets the video renderer.
486: *
487: * @return The video renderer
488: */
489: public VideoRenderer getVideoRenderer(Player player,
490: int sourceWidth, int sourceHeight) {
491: /**
492: * will return NULL until issue with "classByName" creatio
493: * of VideoRenderer/MIDPVideoRenderer will be fixed.
494: * MIDPVideoRenderer will be returneed by derived classes ...
495: */
496: //return new MIDPVideoRenderer(player, sourceWidth, sourceHeight);
497: return null;
498: }
499:
500: /**
501: * Gets the image accessor.
502: *
503: * @return The image accessor
504: */
505: public ImageAccess getImageAccessor() {
506: return imageAccessor;
507: }
508:
509: /**
510: * Gets the tonePlayer attribute of the DefaultConfiguration object
511: *
512: * @return The tonePlayer value
513: */
514: public TonePlayer getTonePlayer() {
515: return myTonePlayer;
516: }
517:
518: protected final static String supportedMPInputTypes[] = {
519: MIME_IMAGE_PNG, MIME_IMAGE_JPEG, MIME_IMAGE_RAW };
520:
521: public String[] getSupportedMediaProcessorInputTypes() {
522: return (needAMMS) ? supportedMPInputTypes : new String[0];
523: }
524:
525: protected final static String supportedSS3DPlayerTypes[] = {
526: MIME_AUDIO_WAV,
527: //MIME_AUDIO_AMR, //MIME_AUDIO_AMR_WB,
528: MIME_AUDIO_MIDI, MIME_AUDIO_SP_MIDI, MIME_AUDIO_TONE };
529:
530: public String[] getSupportedSoundSource3DPlayerTypes() {
531: return (needAMMS && needQSound) ? supportedSS3DPlayerTypes
532: : new String[0];
533: }
534:
535: public String getProperty(String key) {
536: return (String) properties.get(key);
537: }
538:
539: public void setProperty(String key, String value) {
540: properties.put(key, value);
541: }
542:
543: private Object createInstanceOf(String propertyName) {
544: try {
545: String propertyValue = getProperty(propertyName);
546: Class propertyClass = Class.forName(propertyValue);
547: Object propertyInstance = propertyClass.newInstance();
548: return propertyInstance;
549: } catch (Exception e) {
550: return null;
551: }
552: }
553: }
|