root/trunk/libffado/src/ffadodevice.h

Revision 554, 9.0 kB (checked in by ppalmers, 17 years ago)

Merge echoaudio branch into trunk.

This adds support for the Echo Audiofire devices to FFADO. Possibly also other devices working with the Apple Class Driver will work with this code. It is not fully complete yet, but the main rework is
done.

First of all the IAvDevice class/interface is renamed to FFADODevice, in order to separate the AV/C code from the FFADO API code. A device supported by FFADO implements a FFADODevice.

The BeBoB device has been split up into three groups:
- libavc/* : all code and commands that are specified by AV/C specs. Note that a lot of the code that used to be in BeBoB::AvDevice? now resides in AVC::Unit
- genericavc/* : a FFADODevice that uses AV/C descriptors & commands for discovery and config
- bebob/* : the bebob FFADODevice that inherits from GenericAVC::AvDevice? but that uses BridgeCo? commands for discovery

Everything has been moved as high as possible in the class hierarchy. If necessary, a subclass that uses device specific commands is introduced (e.g. BeBoB::Plug inherits from AVC::Plug and uses the
BridgeCo? extended plug info command to discover it's properties).

There are some other fixes along the way that have been done too.

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