root/branches/streaming-rework/src/iavdevice.h

Revision 436, 7.7 kB (checked in by pieterpalmers, 15 years ago)

- fixed verbose level setting
- debugged DICE code, works with EVM

Line 
1 /* iavdevice.h
2  * Copyright (C) 2006 by Daniel Wagner
3  *
4  * This file is part of FreeBoB.
5  *
6  * FreeBoB is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * FreeBoB is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with FreeBoB; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA.
19  */
20
21 #ifndef IAVDEVICE_H
22 #define IAVDEVICE_H
23
24 #include "libavc/avc_definitions.h"
25 #include "libutil/OptionContainer.h"
26 #include "libosc/OscNode.h"
27
28 class ConfigRom;
29 class Ieee1394Service;
30
31 namespace Streaming {
32     class StreamProcessor;
33 }
34 /*!
35 @brief Base class for device support
36
37  This class should be subclassed to implement freebob support
38  for a specific device.
39
40 */
41 class IAvDevice
42     : public Util::OptionContainer,
43       public OSC::OscNode
44 {
45 public:
46         IAvDevice( std::auto_ptr< ConfigRom >( configRom ),
47                     Ieee1394Service& ieee1394service,
48                     int nodeId );
49        
50         virtual ~IAvDevice() {};
51        
52         /// Returns the ConfigRom object of the device node.
53         ConfigRom& getConfigRom() const;
54        
55         /**
56          * @brief This is called by the DeviceManager to discover & configure the device
57          *
58          * @return true if the device was discovered successfuly
59          */
60         virtual bool discover() = 0;
61        
62         /**
63          * @brief Set the samping frequency
64          * @param samplingFrequency
65          * @return true if successful
66          */
67         virtual bool setSamplingFrequency( ESamplingFrequency samplingFrequency ) = 0;
68         /**
69          * @brief get the samplingfrequency as an integer
70          * @return the sampling frequency as integer
71          */
72         virtual int getSamplingFrequency( ) = 0;
73        
74     /**
75      * @brief This is called by the device manager to give the device a unique ID.
76      *
77      * The purpose of this is to allow for unique port naming
78      * in case there are multiple identical devices on the bus.
79      * Some audio API's (e.g. jack) don't work properly when the
80      * port names are not unique.
81      *
82      * Say you have two devices having a port named OutputLeft.
83      * This can cause the streaming
84      * part to present two OutputLeft ports to the audio API,
85      * which won't work. This ID will allow you to construct
86      * the port names as 'dev1_OutputLeft' and 'dev2_OutputLeft'
87      *
88      * @note Currently this is a simple integer that is equal to
89      *       the position of the device in the devicemanager's
90      *       device list. Therefore it is dependant on the order
91      *       in which the devices are detected. The side-effect
92      *       of this is that it is dependant on the bus topology
93      *       and history (e.g. busresets etc). This makes that
94      *       these ID's are not fixed to a specific physical device.
95      *       At some point, we will replaced this with a GUID based
96      *       approach, which is tied to a physiscal device and is
97      *       bus & time independant.
98      *
99      * @param id
100      * @return true if successful
101      */
102     bool setId(unsigned int id);
103        
104         /**
105          * @brief Outputs the device configuration to stderr/stdout [debug helper]
106          *
107          * This function prints out a (detailed) description of the
108          * device detected, and its configuration.
109          */
110         virtual void showDevice() = 0;
111
112         /**
113          * @brief Lock the device
114          *
115          * This is called by the streaming layer before we start manipulating
116          * and/or using the device.
117          *
118          * It should implement the mechanisms provided by the device to
119          * make sure that no other controller claims control of the device.
120          *
121          * @return true if successful, false if not
122          */
123         virtual bool lock() = 0;
124        
125         /**
126          * @brief Unlock the device
127          *
128          * This is called by the streaming layer after we finish manipulating
129          * and/or using the device.
130          *
131          * It should implement the mechanisms provided by the device to
132          * give up exclusive control of the device.
133          *
134          * @return true if successful, false if not
135          */
136         virtual bool unlock() = 0;
137
138     /**
139      * @brief Enable streaming on all 'started' streams
140      *
141      * Enables the ISO streaming on all streams that are 'started'
142      * using startStreamByIndex. This is useful to control a 'master enable'
143      * function on the device.
144      *
145      * @return true if successful
146      */
147     virtual bool enableStreaming();
148    
149     /**
150      * @brief Disable streaming on all streams
151      *
152      * Disables ISO streaming on all streams.
153      * This is useful to control a 'master enable'
154      * function on the device.
155      *
156      * @return true if successful
157      */
158     virtual bool disableStreaming();
159
160         /**
161          * @brief Prepare the device
162          *
163          * This is called by the streaming layer after the configuration
164          * parameters (e.g. sample rate) are set, and before
165          * getStreamProcessor[*] functions are called.
166          *
167          * It should be used to prepare the device's streamprocessors
168          * based upon the device's current configuration. Normally
169          * the streaming layer will not change the device's configuration
170          * after calling this function.
171          *
172          * @return true if successful, false if not
173          */
174         virtual bool prepare() = 0;
175        
176         /**
177          * @brief Returns the number of ISO streams implemented/used by this device
178          *
179          * Most likely this is 2 streams, i.e. one transmit stream and one
180          * receive stream. However there are devices that implement more, for
181          * example BeBoB's implement 4 streams:
182          * - 2 audio streams (1 xmit/1 recv)
183          * - 2 sync streams (1 xmit/1 recv), which are an optional sync source
184          *   for the device.
185          *
186          * @note you have to have a StreamProcessor for every stream. I.e.
187          *       getStreamProcessorByIndex(i) should return a valid StreamProcessor
188          *       for i=0 to i=getStreamCount()-1
189          *
190          * @return number of streams available (both transmit and receive)
191          */
192         virtual int getStreamCount() = 0;
193        
194         /**
195          * @brief Returns the StreamProcessor object for the stream with index i
196          *
197          * @note a streamprocessor returned by getStreamProcessorByIndex(i)
198          *       cannot be the same object as one returned by
199          *       getStreamProcessorByIndex(j) if i isn't equal to j
200          * @note you cannot have two streamprocessors handling the same ISO
201          *       channel (on the same port)
202          *
203          * @param i : Stream index
204          * @pre @ref i smaller than getStreamCount()
205          * @return a StreamProcessor object if successful, NULL otherwise
206          */
207         virtual Streaming::StreamProcessor *getStreamProcessorByIndex(int i) = 0;
208        
209         /**
210          * @brief starts the stream with index i
211          *
212          * This function is called by the streaming layer when this stream should
213          * be started, i.e. the device should start sending data or should be prepared to
214          * be ready to receive data.
215          *
216          * It returns the channel number that was assigned for this stream.
217          * Channel allocation should be done using the allocation functions provided by the
218          * Ieee1394Service object that is passed in the constructor.
219          *
220          * @param i : Stream index
221          * @pre @ref i smaller than getStreamCount()
222          * @return true if successful, false if not
223          */
224         virtual bool startStreamByIndex(int i) = 0;
225        
226         /**
227          * @brief stops the stream with index @ref i
228          *
229          * @param i : Stream index
230          * @pre @ref i smaller than getStreamCount()
231          * @return true if successful, false if not
232          */
233         virtual bool stopStreamByIndex(int i) = 0;
234
235     /**
236      * set verbosity level
237      */
238     virtual void setVerboseLevel(int l);
239
240 protected:
241     std::auto_ptr<ConfigRom>( m_pConfigRom );
242     Ieee1394Service*          m_p1394Service;
243     int                       m_verboseLevel;
244     int                       m_nodeId;
245
246     DECLARE_DEBUG_MODULE;
247 };
248
249 #endif
Note: See TracBrowser for help on using the browser.