root/trunk/libffado/src/iavdevice.h

Revision 529, 8.9 kB (checked in by wagi, 15 years ago)

- saveCache and loadFromCache interface added to IAvDevice
- current implenetation of saveCache and loadFromCache moved to bebob
- config parser added for loading vendor and model ids from a file instead hardcoded (not finished yet)

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 IAVDEVICE_H
26 #define IAVDEVICE_H
27
28 #include "libavc/avc_definitions.h"
29 #include "libutil/OptionContainer.h"
30 #include "libosc/OscNode.h"
31
32 class ConfigRom;
33 class Ieee1394Service;
34
35 namespace Streaming {
36     class StreamProcessor;
37 }
38 /*!
39 @brief Base class for device support
40
41  This class should be subclassed to implement ffado support
42  for a specific device.
43
44 */
45 class IAvDevice
46     : public Util::OptionContainer,
47       public OSC::OscNode
48 {
49 public:
50     IAvDevice( std::auto_ptr< ConfigRom >( configRom ),
51                     Ieee1394Service& ieee1394service,
52                     int nodeId );
53
54     virtual ~IAvDevice() {};
55
56     /// Returns the ConfigRom object of the device node.
57     ConfigRom& getConfigRom() const;
58
59     /**
60      * @brief Called by DeviceManager to load device model from cache.
61      *
62      * This function is called before discover in order to speed up
63      * system initializing.
64      *
65      * @returns true if device was cached and successfully loaded from cache
66      */
67     virtual bool loadFromCache();
68
69     /**
70      * @brief Called by DeviceManager to allow device driver to save a cache version
71      * of the current configuration.
72      *
73      * @returns true if caching was successful. False doesn't mean an error just,
74      * the driver was unable to store the configuration
75      */
76     virtual bool saveCache();
77
78     /**
79      * @brief This is called by the DeviceManager to discover & configure the device
80      *
81      * @return true if the device was discovered successfuly
82      */
83     virtual bool discover() = 0;
84
85     /**
86      * @brief Set the samping frequency
87      * @param samplingFrequency
88      * @return true if successful
89      */
90     virtual bool setSamplingFrequency( ESamplingFrequency samplingFrequency ) = 0;
91     /**
92      * @brief get the samplingfrequency as an integer
93      * @return the sampling frequency as integer
94      */
95     virtual int getSamplingFrequency( ) = 0;
96
97     /**
98      * @brief This is called by the device manager to give the device a unique ID.
99      *
100      * The purpose of this is to allow for unique port naming
101      * in case there are multiple identical devices on the bus.
102      * Some audio API's (e.g. jack) don't work properly when the
103      * port names are not unique.
104      *
105      * Say you have two devices having a port named OutputLeft.
106      * This can cause the streaming
107      * part to present two OutputLeft ports to the audio API,
108      * which won't work. This ID will allow you to construct
109      * the port names as 'dev1_OutputLeft' and 'dev2_OutputLeft'
110      *
111      * @note Currently this is a simple integer that is equal to
112      *       the position of the device in the devicemanager's
113      *       device list. Therefore it is dependant on the order
114      *       in which the devices are detected. The side-effect
115      *       of this is that it is dependant on the bus topology
116      *       and history (e.g. busresets etc). This makes that
117      *       these ID's are not fixed to a specific physical device.
118      *       At some point, we will replaced this with a GUID based
119      *       approach, which is tied to a physiscal device and is
120      *       bus & time independant.
121      *
122      * @param id
123      * @return true if successful
124      */
125     bool setId(unsigned int id);
126
127     /**
128      * @brief Outputs the device configuration to stderr/stdout [debug helper]
129      *
130      * This function prints out a (detailed) description of the
131      * device detected, and its configuration.
132      */
133     virtual void showDevice() = 0;
134
135     /**
136      * @brief Lock the device
137      *
138      * This is called by the streaming layer before we start manipulating
139      * and/or using the device.
140      *
141      * It should implement the mechanisms provided by the device to
142      * make sure that no other controller claims control of the device.
143      *
144      * @return true if successful, false if not
145      */
146     virtual bool lock() = 0;
147
148     /**
149      * @brief Unlock the device
150      *
151      * This is called by the streaming layer after we finish manipulating
152      * and/or using the device.
153      *
154      * It should implement the mechanisms provided by the device to
155      * give up exclusive control of the device.
156      *
157      * @return true if successful, false if not
158      */
159     virtual bool unlock() = 0;
160
161     /**
162      * @brief Enable streaming on all 'started' streams
163      *
164      * Enables the ISO streaming on all streams that are 'started'
165      * using startStreamByIndex. This is useful to control a 'master enable'
166      * function on the device.
167      *
168      * @return true if successful
169      */
170     virtual bool enableStreaming();
171
172     /**
173      * @brief Disable streaming on all streams
174      *
175      * Disables ISO streaming on all streams.
176      * This is useful to control a 'master enable'
177      * function on the device.
178      *
179      * @return true if successful
180      */
181     virtual bool disableStreaming();
182
183     /**
184      * @brief Prepare the device
185      *
186      * This is called by the streaming layer after the configuration
187      * parameters (e.g. sample rate) are set, and before
188      * getStreamProcessor[*] functions are called.
189      *
190      * It should be used to prepare the device's streamprocessors
191      * based upon the device's current configuration. Normally
192      * the streaming layer will not change the device's configuration
193      * after calling this function.
194      *
195      * @return true if successful, false if not
196      */
197     virtual bool prepare() = 0;
198
199     /**
200      * @brief Returns the number of ISO streams implemented/used by this device
201      *
202      * Most likely this is 2 streams, i.e. one transmit stream and one
203      * receive stream. However there are devices that implement more, for
204      * example BeBoB's implement 4 streams:
205      * - 2 audio streams (1 xmit/1 recv)
206      * - 2 sync streams (1 xmit/1 recv), which are an optional sync source
207      *   for the device.
208      *
209      * @note you have to have a StreamProcessor for every stream. I.e.
210      *       getStreamProcessorByIndex(i) should return a valid StreamProcessor
211      *       for i=0 to i=getStreamCount()-1
212      *
213      * @return number of streams available (both transmit and receive)
214      */
215     virtual int getStreamCount() = 0;
216
217     /**
218      * @brief Returns the StreamProcessor object for the stream with index i
219      *
220      * @note a streamprocessor returned by getStreamProcessorByIndex(i)
221      *       cannot be the same object as one returned by
222      *       getStreamProcessorByIndex(j) if i isn't equal to j
223      * @note you cannot have two streamprocessors handling the same ISO
224      *       channel (on the same port)
225      *
226      * @param i : Stream index
227      * @pre @ref i smaller than getStreamCount()
228      * @return a StreamProcessor object if successful, NULL otherwise
229      */
230     virtual Streaming::StreamProcessor *getStreamProcessorByIndex(int i) = 0;
231
232     /**
233      * @brief starts the stream with index i
234      *
235      * This function is called by the streaming layer when this stream should
236      * be started, i.e. the device should start sending data or should be prepared to
237      * be ready to receive data.
238      *
239      * It returns the channel number that was assigned for this stream.
240      * Channel allocation should be done using the allocation functions provided by the
241      * Ieee1394Service object that is passed in the constructor.
242      *
243      * @param i : Stream index
244      * @pre @ref i smaller than getStreamCount()
245      * @return true if successful, false if not
246      */
247     virtual bool startStreamByIndex(int i) = 0;
248
249     /**
250      * @brief stops the stream with index @ref i
251      *
252      * @param i : Stream index
253      * @pre @ref i smaller than getStreamCount()
254      * @return true if successful, false if not
255      */
256     virtual bool stopStreamByIndex(int i) = 0;
257
258     /**
259      * set verbosity level
260      */
261     virtual void setVerboseLevel(int l);
262
263     /**
264      * @brief return the node id of this device
265      *
266      * @return the node id
267      */
268     int getNodeId() { return m_nodeId;};
269
270 protected:
271     std::auto_ptr<ConfigRom>( m_pConfigRom );
272     Ieee1394Service*          m_p1394Service;
273     int                       m_verboseLevel;
274     int                       m_nodeId;
275
276     DECLARE_DEBUG_MODULE;
277 };
278
279 #endif
Note: See TracBrowser for help on using the browser.