OSDN Git Service

[TAG]NyARToolkit-2.0.0
[nyartoolkit-and/nyartoolkit-and.git] / branches / nyatla / src.utils / jmf / jp / nyatla / nyartoolkit / jmf / utils / MonitorCDS.java
1 /*
2  * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
3  *
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.
9  *
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.
21  *
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.
27  */
28 package jp.nyatla.nyartoolkit.jmf.utils;
29
30
31 import javax.media.*;
32 import javax.media.protocol.*;
33 import javax.media.control.*;
34
35 import java.io.IOException;
36
37
38
39 public class MonitorCDS extends PushBufferDataSource{
40
41     private PushBufferDataSource delegate = null;
42     private PushBufferStream [] delStreams = null;
43     private MonitorStream monitorStream = null;
44     private PushBufferStream [] monitorStreams = null;
45     boolean delStarted = false; // variable used by MonitorStream also
46     private Control [] controls;
47
48     public MonitorCDS(DataSource ds)
49     {
50         // Get the stream from the actual datasource
51         // and create a MonitorStream from it
52         // Export the MonitorControl interface of the MonitorStream
53         if (ds instanceof PushBufferDataSource)
54         {
55             delegate = (PushBufferDataSource) ds;
56             delStreams = delegate.getStreams();
57             monitorStream = new MonitorStream(delStreams[0], this);
58             monitorStreams = new PushBufferStream[] {monitorStream};
59         }
60     }
61
62     public Object [] getControls()
63     {
64         return controls;
65     }
66
67     public Object getControl(String value) {
68         if (value.equals("jmfsample.MonitorStream") || value.equals("javax.media.control.MonitorControl"))
69             return monitorStream;
70         else
71             return null;
72     }
73
74     public javax.media.CaptureDeviceInfo getCaptureDeviceInfo()
75     {
76         return ((CaptureDevice)delegate).getCaptureDeviceInfo();
77     }
78
79     public FormatControl[] getFormatControls()
80     {
81         return ((CaptureDevice)delegate).getFormatControls();
82     }
83
84     public String getContentType()
85     {
86         return delegate.getContentType();
87     }
88
89     public void connect() throws IOException
90     {
91         if (delegate == null)
92             throw new IOException("Incompatible DataSource");
93         // Delegate is already connected
94     }
95
96     public void disconnect()
97     {
98         monitorStream.setEnabled(false);
99         delegate.disconnect();
100     }
101
102     public synchronized void start() throws IOException
103     {
104         startDelegate();
105         delStarted = true;
106     }
107
108     public synchronized void stop() throws IOException
109     {
110         if (!monitorStream.isEnabled()) {
111             stopDelegate();
112         }
113         delStarted = false;
114     }
115
116     public Time getDuration()
117     {
118         return delegate.getDuration();
119     }
120
121     public PushBufferStream [] getStreams()
122     {
123         return monitorStreams;
124     }
125
126     void startDelegate() throws IOException
127     {
128         delegate.start();
129     }
130
131     void stopDelegate() throws IOException
132     {
133         delegate.stop();
134     }
135
136 }