root/branches/echoaudio/src/ffadodevice.h

Revision 509, 8.4 kB (checked in by ppalmers, 15 years ago)

- Moved all generic stuff but the functionblocks over to libavc
- compiles and works

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