root/branches/streaming-rework/src/iavdevice.h

Revision 426, 7.5 kB (checked in by pieterpalmers, 15 years ago)

- changed the IAvDevice from an interface to a base class,

since there is some code duplication starting to
appear.

Line 
1 /* iavdevice.h
2  * Copyright (C) 2006 by Daniel Wagner
3  *
4  * This file is part of FreeBoB.
5  *
6  * FreeBoB is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * FreeBoB is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with FreeBoB; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA.
19  */
20
21 #ifndef IAVDEVICE_H
22 #define IAVDEVICE_H
23
24 #include "libavc/avc_definitions.h"
25 #include "libfreebob/xmlparser.h"
26 #include "libutil/OptionContainer.h"
27
28 class ConfigRom;
29 class Ieee1394Service;
30
31 namespace Streaming {
32     class StreamProcessor;
33 }
34 /*!
35 @brief Base class for device support
36
37  This class should be subclassed to implement freebob support
38  for a specific device.
39
40 */
41 class IAvDevice : public Util::OptionContainer {
42 public:
43         IAvDevice( std::auto_ptr< ConfigRom >( configRom ),
44                     Ieee1394Service& ieee1394service,
45                     int nodeId );
46        
47         virtual ~IAvDevice() {};
48        
49         /// Returns the ConfigRom object of the device node.
50         ConfigRom& getConfigRom() const;
51        
52         /**
53          * @brief This is called by the DeviceManager to discover & configure the device
54          *
55          * @return true if the device was discovered successfuly
56          */
57         virtual bool discover() = 0;
58        
59         /**
60          * @brief Set the samping frequency
61          * @param samplingFrequency
62          * @return true if successful
63          */
64         virtual bool setSamplingFrequency( ESamplingFrequency samplingFrequency ) = 0;
65         /**
66          * @brief get the samplingfrequency as an integer
67          * @return the sampling frequency as integer
68          */
69         virtual int getSamplingFrequency( ) = 0;
70        
71     /**
72      * @brief This is called by the device manager to give the device a unique ID.
73      *
74      * The purpose of this is to allow for unique port naming
75      * in case there are multiple identical devices on the bus.
76      * Some audio API's (e.g. jack) don't work properly when the
77      * port names are not unique.
78      *
79      * Say you have two devices having a port named OutputLeft.
80      * This can cause the streaming
81      * part to present two OutputLeft ports to the audio API,
82      * which won't work. This ID will allow you to construct
83      * the port names as 'dev1_OutputLeft' and 'dev2_OutputLeft'
84      *
85      * @note Currently this is a simple integer that is equal to
86      *       the position of the device in the devicemanager's
87      *       device list. Therefore it is dependant on the order
88      *       in which the devices are detected. The side-effect
89      *       of this is that it is dependant on the bus topology
90      *       and history (e.g. busresets etc). This makes that
91      *       these ID's are not fixed to a specific physical device.
92      *       At some point, we will replaced this with a GUID based
93      *       approach, which is tied to a physiscal device and is
94      *       bus & time independant.
95      *
96      * @param id
97      * @return true if successful
98      */
99     bool setId(unsigned int id);
100        
101         /**
102          * @brief Constructs an XML description of the device [obsolete]
103          *
104          * this is a leftover from v1.0 and isn't used
105          * just provide an empty implementation that returns true
106          * untill it is removed
107          *
108          * @param deviceNode
109          * @return true if successful, false if not
110          */
111         bool addXmlDescription( xmlNodePtr deviceNode ) {return true;};
112        
113         /**
114          * @brief Outputs the device configuration to stderr/stdout [debug helper]
115          *
116          * This function prints out a (detailed) description of the
117          * device detected, and its configuration.
118          */
119         virtual void showDevice() const = 0;
120
121         /**
122          * @brief Lock the device
123          *
124          * This is called by the streaming layer before we start manipulating
125          * and/or using the device.
126          *
127          * It should implement the mechanisms provided by the device to
128          * make sure that no other controller claims control of the device.
129          *
130          * @return true if successful, false if not
131          */
132         virtual bool lock() = 0;
133        
134         /**
135          * @brief Unlock the device
136          *
137          * This is called by the streaming layer after we finish manipulating
138          * and/or using the device.
139          *
140          * It should implement the mechanisms provided by the device to
141          * give up exclusive control of the device.
142          *
143          * @return true if successful, false if not
144          */
145         virtual bool unlock() = 0;
146
147         /**
148          * @brief Prepare the device
149          *
150          * This is called by the streaming layer after the configuration
151          * parameters (e.g. sample rate) are set, and before
152          * getStreamProcessor[*] functions are called.
153          *
154          * It should be used to prepare the device's streamprocessors
155          * based upon the device's current configuration. Normally
156          * the streaming layer will not change the device's configuration
157          * after calling this function.
158          *
159          * @return true if successful, false if not
160          */
161         virtual bool prepare() = 0;
162        
163         /**
164          * @brief Returns the number of ISO streams implemented/used by this device
165          *
166          * Most likely this is 2 streams, i.e. one transmit stream and one
167          * receive stream. However there are devices that implement more, for
168          * example BeBoB's implement 4 streams:
169          * - 2 audio streams (1 xmit/1 recv)
170          * - 2 sync streams (1 xmit/1 recv), which are an optional sync source
171          *   for the device.
172          *
173          * @note you have to have a StreamProcessor for every stream. I.e.
174          *       getStreamProcessorByIndex(i) should return a valid StreamProcessor
175          *       for i=0 to i=getStreamCount()-1
176          *
177          * @return number of streams available (both transmit and receive)
178          */
179         virtual int getStreamCount() = 0;
180        
181         /**
182          * @brief Returns the StreamProcessor object for the stream with index i
183          *
184          * @note a streamprocessor returned by getStreamProcessorByIndex(i)
185          *       cannot be the same object as one returned by
186          *       getStreamProcessorByIndex(j) if i isn't equal to j
187          * @note you cannot have two streamprocessors handling the same ISO
188          *       channel (on the same port)
189          *
190          * @param i : Stream index
191          * @pre @ref i smaller than getStreamCount()
192          * @return a StreamProcessor object if successful, NULL otherwise
193          */
194         virtual Streaming::StreamProcessor *getStreamProcessorByIndex(int i) = 0;
195        
196         /**
197          * @brief starts the stream with index i
198          *
199          * This function is called by the streaming layer when this stream should
200          * be started, i.e. the device should start sending data or should be prepared to
201          * be ready to receive data.
202          *
203          * It returns the channel number that was assigned for this stream.
204          * Channel allocation should be done using the allocation functions provided by the
205          * Ieee1394Service object that is passed in the constructor.
206          *
207          * @param i : Stream index
208          * @pre @ref i smaller than getStreamCount()
209          * @return true if successful, false if not
210          */
211         virtual bool startStreamByIndex(int i) = 0;
212        
213         /**
214          * @brief stops the stream with index @ref i
215          *
216          * @param i : Stream index
217          * @pre @ref i smaller than getStreamCount()
218          * @return true if successful, false if not
219          */
220         virtual bool stopStreamByIndex(int i) = 0;
221
222     /**
223      * set verbosity level
224      */
225     virtual void setVerboseLevel(int l);
226
227 protected:
228     std::auto_ptr<ConfigRom>( m_pConfigRom );
229     Ieee1394Service*          m_p1394Service;
230     int                       m_verboseLevel;
231     int                       m_nodeId;
232
233     DECLARE_DEBUG_MODULE;
234 };
235
236 #endif
Note: See TracBrowser for help on using the browser.