2 * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
4 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
5 * modify and redistribute this software in source and binary code form,
6 * provided that i) this copyright notice and license appear on all copies of
7 * the software; and ii) Licensee does not utilize the software in a manner
8 * which is disparaging to Sun.
10 * This software is provided "AS IS," without a warranty of any kind. ALL
11 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
12 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
13 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
14 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
15 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
16 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
17 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
18 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
19 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
20 * POSSIBILITY OF SUCH DAMAGES.
22 * This software is not designed or intended for use in on-line control of
23 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
24 * the design, construction, operation or maintenance of any nuclear
25 * facility. Licensee represents and warrants that it will not use or
26 * redistribute the Software for such purposes.
28 package jp.nyatla.nyartoolkit.jmf.utils;
31 import javax.media.protocol.*;
33 import javax.media.util.BufferToImage;
34 import java.io.IOException;
37 public class MonitorStream implements PushBufferStream, BufferTransferHandler
40 JmfCaptureListener img_listener;
42 PushBufferStream actual = null;
44 boolean dataAvailable = false;
46 boolean terminate = false;
48 boolean enabled = false;
50 Object bufferLock = new Object();
52 Buffer cbuffer = new Buffer();
54 BufferTransferHandler transferHandler = null;
56 Component component = null;
60 BufferToImage bti = null;
62 MonitorStream(PushBufferStream actual, MonitorCDS cds)
65 actual.setTransferHandler(this);
69 public javax.media.Format getFormat()
71 return actual.getFormat();
77 public void read(Buffer buffer) throws IOException
79 // Wait for data to be available
80 // Doesn't get used much because the transferData
81 // call is made when data IS available. And most
82 // Processors/Players read the data in the same
83 // thread that called transferData, although that's
84 // not a safe assumption to make
86 synchronized (bufferLock) {
87 while (!dataAvailable && !terminate) {
90 } catch (InterruptedException ie) {
97 synchronized (bufferLock) {
98 // Copy the buffer attributes, but swap the data
99 // attributes so that no extra copy is made.
100 buffer.copy(cbuffer, true);
101 //dataAvailable = false;
107 public void setCaptureListener(JmfCaptureListener i_listener)
109 img_listener = i_listener;
112 public void transferData(PushBufferStream pbs)
114 // Get the data from the original source stream
115 synchronized (bufferLock) {
118 } catch (IOException ioe) {
121 dataAvailable = true;
122 bufferLock.notifyAll();
124 if (img_listener != null) {
125 img_listener.onUpdateBuffer(cbuffer);
128 // Maybe synchronize this with setTransferHandler() ?
129 if (transferHandler != null && cds.delStarted)
130 transferHandler.transferData(this);
133 public void setTransferHandler(BufferTransferHandler transferHandler)
135 this.transferHandler = transferHandler;
138 public boolean setEnabled(boolean value)
141 if (value == false) {
142 if (!cds.delStarted) {
145 } catch (IOException ioe) {
149 // Start the capture datasource if the monitor is enabled
152 } catch (IOException ioe) {
158 public boolean isEnabled()
163 public float setPreviewFrameRate(float rate)
165 System.err.println("TODO");
169 public ContentDescriptor getContentDescriptor()
171 return actual.getContentDescriptor();
174 public long getContentLength()
176 return actual.getContentLength();
179 public boolean endOfStream()
181 return actual.endOfStream();
184 public Object[] getControls()
186 return new Object[0];
189 public Object getControl(String str)