root/trunk/libffado/src/ffadodevice.h

Revision 587, 10.4 kB (checked in by ppalmers, 17 years ago)

- moved all vendor id's to one include file
- introduced the framework for the ECHO FireWorks? platform

Line 
1 /*
2  * Copyright (C) 2005-2007 by Daniel Wagner
3  * Copyright (C) 2005-2007 by Pieter Palmers
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License version 2.1, as published by the Free Software Foundation;
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22  * MA 02110-1301 USA
23  */
24
25 #ifndef FFADODEVICE_H
26 #define FFADODEVICE_H
27
28 #include "libutil/OptionContainer.h"
29 #include "libcontrol/BasicElements.h"
30
31 #include "libieee1394/vendor_model_ids.h"
32
33 class ConfigRom;
34 class Ieee1394Service;
35
36 namespace Streaming {
37     class StreamProcessor;
38 }
39
40 /*!
41 @brief Base class for device support
42
43  This class should be subclassed to implement ffado support
44  for a specific device.
45
46 */
47 class FFADODevice
48     : public Util::OptionContainer,
49       public Control::Container
50 {
51 public:
52     FFADODevice( Ieee1394Service& ieee1394service,
53                  std::auto_ptr< ConfigRom >( configRom ) );
54
55     virtual ~FFADODevice() {};
56
57    
58     /**
59      * @brief Compares the GUID of two FFADODevices
60      *
61      * This function compares the GUID of two FFADODevices and returns true
62      * if the GUID of @ref a is larger than the GUID of @ref b . This is intended
63      * to be used with the STL sort() algorithm.
64      *
65      * Note that GUID's are converted to integers for this.
66      *
67      * @param a pointer to first FFADODevice
68      * @param b pointer to second FFADODevice
69      *
70      * @returns true if the GUID of @ref a is larger than the GUID of @ref b .
71      */
72     static bool compareGUID( FFADODevice *a, FFADODevice *b );
73
74     /// Returns the 1394 service of the FFADO device
75     virtual Ieee1394Service& get1394Service()
76         { return *m_p1394Service; };
77     /// Returns the ConfigRom object of the device node.
78     virtual ConfigRom& getConfigRom() const;
79    
80     /**
81      * @brief Called by DeviceManager to load device model from cache.
82      *
83      * This function is called before discover in order to speed up
84      * system initializing.
85      *
86      * @returns true if device was cached and successfully loaded from cache
87      */
88     virtual bool loadFromCache();
89
90     /**
91      * @brief Called by DeviceManager to allow device driver to save a cache version
92      * of the current configuration.
93      *
94      * @returns true if caching was successful. False doesn't mean an error just,
95      * the driver was unable to store the configuration
96      */
97     virtual bool saveCache();
98
99     /**
100      * @brief This is called by the DeviceManager to create an instance of the device
101      *
102      * This function enables the FFADODevice to return a subclass of itself should that
103      * be needed. If we don't do this we'd need to know about the subclasses in the
104      * devicemanager, whilst now we don't.
105      *
106      * The function should return an instance of either the class itself or a subclass
107      * of itself.
108      *
109      * This should be overridden in any subclass.
110      *
111      * @return a new instance of the AvDevice type, NULL when unsuccessful
112      */
113     static FFADODevice * createDevice( Ieee1394Service& ,
114                                         std::auto_ptr<ConfigRom>( x ));
115
116     /**
117      * @brief This is called by the DeviceManager to discover & configure the device
118      *
119      * @return true if the device was discovered successfuly
120      */
121     virtual bool discover() = 0;
122
123     /**
124      * @brief Set the samping frequency
125      * @param samplingFrequency
126      * @return true if successful
127      */
128     virtual bool setSamplingFrequency( int samplingFrequency ) = 0;
129     /**
130      * @brief get the samplingfrequency as an integer
131      * @return the sampling frequency as integer
132      */
133     virtual int getSamplingFrequency( ) = 0;
134
135     /**
136      * @brief This is called by the device manager to give the device a unique ID.
137      *
138      * The purpose of this is to allow for unique port naming
139      * in case there are multiple identical devices on the bus.
140      * Some audio API's (e.g. jack) don't work properly when the
141      * port names are not unique.
142      *
143      * Say you have two devices having a port named OutputLeft.
144      * This can cause the streaming
145      * part to present two OutputLeft ports to the audio API,
146      * which won't work. This ID will allow you to construct
147      * the port names as 'dev1_OutputLeft' and 'dev2_OutputLeft'
148      *
149      * @note Currently this is a simple integer that is equal to
150      *       the position of the device in the devicemanager's
151      *       device list. Therefore it is dependant on the order
152      *       in which the devices are detected. The side-effect
153      *       of this is that it is dependant on the bus topology
154      *       and history (e.g. busresets etc). This makes that
155      *       these ID's are not fixed to a specific physical device.
156      *       At some point, we will replaced this with a GUID based
157      *       approach, which is tied to a physical device and is
158      *       bus & time independant.
159      *
160      * @param id
161      * @return true if successful
162      */
163     bool setId(unsigned int id);
164
165     /**
166      * @brief Outputs the device configuration to stderr/stdout [debug helper]
167      *
168      * This function prints out a (detailed) description of the
169      * device detected, and its configuration.
170      */
171     virtual void showDevice();
172
173     /**
174      * @brief Lock the device
175      *
176      * This is called by the streaming layer before we start manipulating
177      * and/or using the device.
178      *
179      * It should implement the mechanisms provided by the device to
180      * make sure that no other controller claims control of the device.
181      *
182      * @return true if successful, false if not
183      */
184     virtual bool lock() = 0;
185
186     /**
187      * @brief Unlock the device
188      *
189      * This is called by the streaming layer after we finish manipulating
190      * and/or using the device.
191      *
192      * It should implement the mechanisms provided by the device to
193      * give up exclusive control of the device.
194      *
195      * @return true if successful, false if not
196      */
197     virtual bool unlock() = 0;
198
199     /**
200      * @brief Enable streaming on all 'started' streams
201      *
202      * Enables the ISO streaming on all streams that are 'started'
203      * using startStreamByIndex. This is useful to control a 'master enable'
204      * function on the device.
205      *
206      * @return true if successful
207      */
208     virtual bool enableStreaming();
209
210     /**
211      * @brief Disable streaming on all streams
212      *
213      * Disables ISO streaming on all streams.
214      * This is useful to control a 'master enable'
215      * function on the device.
216      *
217      * @return true if successful
218      */
219     virtual bool disableStreaming();
220
221     /**
222      * @brief Prepare the device
223      *
224      * This is called by the streaming layer after the configuration
225      * parameters (e.g. sample rate) are set, and before
226      * getStreamProcessor[*] functions are called.
227      *
228      * It should be used to prepare the device's streamprocessors
229      * based upon the device's current configuration. Normally
230      * the streaming layer will not change the device's configuration
231      * after calling this function.
232      *
233      * @return true if successful, false if not
234      */
235     virtual bool prepare() = 0;
236
237     /**
238      * @brief Returns the number of ISO streams implemented/used by this device
239      *
240      * Most likely this is 2 streams, i.e. one transmit stream and one
241      * receive stream. However there are devices that implement more, for
242      * example BeBoB's implement 4 streams:
243      * - 2 audio streams (1 xmit/1 recv)
244      * - 2 sync streams (1 xmit/1 recv), which are an optional sync source
245      *   for the device.
246      *
247      * @note you have to have a StreamProcessor for every stream. I.e.
248      *       getStreamProcessorByIndex(i) should return a valid StreamProcessor
249      *       for i=0 to i=getStreamCount()-1
250      *
251      * @return number of streams available (both transmit and receive)
252      */
253     virtual int getStreamCount() = 0;
254
255     /**
256      * @brief Returns the StreamProcessor object for the stream with index i
257      *
258      * @note a streamprocessor returned by getStreamProcessorByIndex(i)
259      *       cannot be the same object as one returned by
260      *       getStreamProcessorByIndex(j) if i isn't equal to j
261      * @note you cannot have two streamprocessors handling the same ISO
262      *       channel (on the same port)
263      *
264      * @param i : Stream index
265      * @pre @ref i smaller than getStreamCount()
266      * @return a StreamProcessor object if successful, NULL otherwise
267      */
268     virtual Streaming::StreamProcessor *getStreamProcessorByIndex(int i) = 0;
269
270     /**
271      * @brief starts the stream with index i
272      *
273      * This function is called by the streaming layer when this stream should
274      * be started, i.e. the device should start sending data or should be prepared to
275      * be ready to receive data.
276      *
277      * It returns the channel number that was assigned for this stream.
278      * Channel allocation should be done using the allocation functions provided by the
279      * Ieee1394Service object that is passed in the constructor.
280      *
281      * @param i : Stream index
282      * @pre @ref i smaller than getStreamCount()
283      * @return true if successful, false if not
284      */
285     virtual bool startStreamByIndex(int i) = 0;
286
287     /**
288      * @brief stops the stream with index @ref i
289      *
290      * @param i : Stream index
291      * @pre @ref i smaller than getStreamCount()
292      * @return true if successful, false if not
293      */
294     virtual bool stopStreamByIndex(int i) = 0;
295
296     /**
297      * set verbosity level
298      */
299     virtual void setVerboseLevel(int l);
300
301     /**
302      * @brief return the node id of this device
303      *
304      * @return the node id
305      */
306     int getNodeId();
307
308     // the Control::Container functions
309     virtual std::string getName();
310     virtual bool setName( std::string n )
311         { return false; };
312
313
314 protected:
315     std::auto_ptr<ConfigRom>( m_pConfigRom );
316     Ieee1394Service*          m_p1394Service;
317
318     DECLARE_DEBUG_MODULE;
319 };
320
321 #endif
Note: See TracBrowser for help on using the browser.