OSDN Git Service

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