root/trunk/libffado/src/iavdevice.h

Revision 516, 8.3 kB (checked in by wagi, 15 years ago)

- some de/serialing bugs found and fixed
- caching enabled for bebob devices

(finally online again! big thanks to my free wireless internet provider. s/he is finally back from
her/his holiday :)

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