root/trunk/libffado/src/iavdevice.h

Revision 479, 8.7 kB (checked in by wagi, 15 years ago)

- added all missing 'virtual' to function declared in avdevice implementation
- added getConfigurationId function (used for av/c model caching)

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