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;
33 import javax.media.protocol.*;
35 import javax.media.util.BufferToImage;
36 import java.io.IOException;
39 public class MonitorStream implements PushBufferStream, BufferTransferHandler {
41 JmfCaptureListener img_listener;
42 PushBufferStream actual = null;
43 boolean dataAvailable = false;
44 boolean terminate = false;
45 boolean enabled = false;
46 Object bufferLock = new Object();
47 Buffer cbuffer = new Buffer();
48 BufferTransferHandler transferHandler = null;
49 Component component = null;
51 BufferToImage bti = null;
53 MonitorStream(PushBufferStream actual, MonitorCDS cds) {
55 actual.setTransferHandler(this);
59 public javax.media.Format getFormat()
61 return actual.getFormat();
66 public void read(Buffer buffer) throws IOException
68 // Wait for data to be available
69 // Doesn't get used much because the transferData
70 // call is made when data IS available. And most
71 // Processors/Players read the data in the same
72 // thread that called transferData, although that's
73 // not a safe assumption to make
75 synchronized (bufferLock) {
76 while (!dataAvailable && !terminate) {
79 } catch (InterruptedException ie) {
86 synchronized (bufferLock) {
87 // Copy the buffer attributes, but swap the data
88 // attributes so that no extra copy is made.
89 buffer.copy(cbuffer, true);
90 //dataAvailable = false;
95 public void setCaptureListener(JmfCaptureListener i_listener)
97 img_listener=i_listener;
100 public void transferData(PushBufferStream pbs)
102 // Get the data from the original source stream
103 synchronized (bufferLock) {
106 } catch (IOException ioe) {
109 dataAvailable = true;
110 bufferLock.notifyAll();
112 if(img_listener!=null){
113 img_listener.onUpdateBuffer(cbuffer);
117 // Display data if monitor is active
120 VideoFormat vf = (VideoFormat) cbuffer.getFormat();
121 bti = new BufferToImage(vf);
123 if (bti != null && component != null) {
124 Image im = bti.createImage(cbuffer);
125 Graphics g = component.getGraphics();
126 Dimension size = component.getSize();
128 g.drawImage(im, 0, 0, component);
132 // Maybe synchronize this with setTransferHandler() ?
133 if (transferHandler != null && cds.delStarted)
134 transferHandler.transferData(this);
137 public void setTransferHandler(BufferTransferHandler transferHandler) {
138 this.transferHandler = transferHandler;
141 public boolean setEnabled(boolean value) {
143 if (value == false) {
144 if (!cds.delStarted) {
147 } catch (IOException ioe) {
151 // Start the capture datasource if the monitor is enabled
154 }catch (IOException ioe) {
160 public boolean isEnabled()
167 public float setPreviewFrameRate(float rate)
169 System.err.println("TODO");
173 public ContentDescriptor getContentDescriptor()
175 return actual.getContentDescriptor();
178 public long getContentLength()
180 return actual.getContentLength();
183 public boolean endOfStream() {
184 return actual.endOfStream();
187 public Object [] getControls() {
188 return new Object[0];
191 public Object getControl(String str) {