1 package com.inzyme.jmds; 2 3 import java.awt.Component ; 4 import java.io.IOException ; 5 6 import javax.media.Format; 7 import javax.media.Owned; 8 import javax.media.Time; 9 import javax.media.control.FormatControl; 10 import javax.media.protocol.PushBufferDataSource; 11 import javax.media.protocol.PushBufferStream; 12 13 18 public class DSDataSource extends PushBufferDataSource { 19 private DSSourceStream myStream; 20 private DSCapturePin myCapturePin; 21 22 private boolean myCrossBarLoaded; 23 private DSCrossBar myCrossBar; 24 25 private FormatControl myFormatControl; 26 27 32 public DSDataSource(DSCapturePin _capturePin) { 33 myCapturePin = _capturePin; 34 myStream = new DSSourceStream(_capturePin); 35 myFormatControl = new DSDataSourceFormatControl(); 36 } 37 38 43 public PushBufferStream[] getStreams() { 44 return new PushBufferStream[] { myStream }; 45 } 46 47 52 public String getContentType() { 53 return myStream.getContentDescriptor().getContentType(); 54 } 55 56 59 public void connect() throws IOException { 60 myStream.connect(); 61 } 62 63 66 public void disconnect() { 67 myStream.disconnect(); 68 } 69 70 73 public void start() throws IOException { 74 myStream.start(); 75 } 76 77 80 public void stop() throws IOException { 81 myStream.stop(); 82 } 83 84 91 public Object [] getControls() { 92 return new Object [] { myFormatControl }; 93 } 94 95 102 public Object getControl(String _controlClass) { 103 Object control = null; 104 if (FormatControl.class.getName().equals(_controlClass)) { 105 control = myFormatControl; 106 } 107 return control; 108 } 109 110 113 public Time getDuration() { 114 return Time.TIME_UNKNOWN; 115 } 116 117 123 public boolean hasCrossBar() { 124 ensureCrossBarLoaded(); 125 return myCrossBar != null; 126 } 127 128 134 public DSCrossBar getCrossBar() { 135 ensureCrossBarLoaded(); 136 return myCrossBar; 137 } 138 139 private void ensureCrossBarLoaded() { 140 if (!myCrossBarLoaded) { 141 myCrossBar = getCrossBar0(); 142 myCrossBarLoaded = true; 143 } 144 } 145 146 private native DSCrossBar getCrossBar0(); 147 148 public class DSDataSourceFormatControl implements FormatControl, Owned { 149 public Component getControlComponent() { 150 return null; 151 } 152 153 public Format[] getSupportedFormats() { 154 return myCapturePin.getFormats(); 155 } 156 157 public boolean isEnabled() { 158 return true; 159 } 160 161 public void setEnabled(boolean _enabled) { 162 } 163 164 public Format getFormat() { 165 return myStream.getFormat(); 166 } 167 168 public Object getOwner() { 169 return DSDataSource.this; 170 } 171 172 176 public Format setFormat(Format _format) { 177 int matchingIndex = -1; 178 Format[] formats = getSupportedFormats(); 179 for (int i = 0; matchingIndex == -1 && i < formats.length; i ++) { 180 if (formats[i].matches(_format)) { 181 matchingIndex = i; 182 } 183 } 184 if (matchingIndex == -1) { 185 return myStream.getFormat(); 186 } 187 else { 188 return myStream.setFormat(matchingIndex); 189 } 190 } 191 } 192 } 193 | Popular Tags |