root/trunk/libffado/src/libavc/general/avc_plug.h

Revision 1336, 12.3 kB (checked in by ppalmers, 14 years ago)

Bring trunk up to date with branches/libffado-2.0:

"""
svn merge -r 1254:1299 svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0
svn merge -r 1301:1320 svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0
svn merge -r 1322:1323 svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0
svn merge -r 1329:HEAD svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0
"""

Add getSupportedSamplingFrequencies() to DICE, RME and Metric Halo AvDevices?

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  * Copyright (C) 2005-2008 by Daniel Wagner
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 program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 2 of the License, or
13  * (at your option) version 3 of the License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #ifndef AVC_PLUG
26 #define AVC_PLUG
27
28 #include "../ccm/avc_signal_source.h"
29 #include "../streamformat/avc_extended_stream_format.h"
30 #include "../avc_definitions.h"
31 #include "avc_generic.h"
32
33 #include "libutil/serialize.h"
34
35 #include "debugmodule/debugmodule.h"
36
37 #include <string>
38
39 class Ieee1394Service;
40 class ConfigRom;
41
42 namespace AVC {
43
44 class Unit;
45 class Subunit;
46 class PlugManager;
47
48 class Plug;
49 typedef std::vector<Plug*> PlugVector;
50
51 class PlugConnection;
52 typedef std::vector<PlugConnection*> PlugConnectionVector;
53
54
55 class Plug {
56 public:
57
58     enum EPlugAddressType {
59         eAPA_PCR,
60         eAPA_ExternalPlug,
61         eAPA_AsynchronousPlug,
62         eAPA_SubunitPlug,
63         eAPA_FunctionBlockPlug,
64         eAPA_Undefined,
65     };
66     std::string plugAddressTypeToString(enum EPlugAddressType t);
67
68     enum EPlugType {
69         eAPT_IsoStream,
70         eAPT_AsyncStream,
71         eAPT_Midi,
72         eAPT_Sync,
73         eAPT_Analog,
74         eAPT_Digital,
75         eAPT_Unknown,
76     };
77     std::string plugTypeToString(enum EPlugType t);
78
79     enum EPlugDirection {
80         eAPD_Input,
81         eAPD_Output,
82         eAPD_Unknown,
83     };
84     std::string plugDirectionToString(enum EPlugDirection t);
85
86     // \todo This constructors sucks. too many parameters. fix it.
87     Plug( Unit* unit,
88           Subunit* subunit,
89           function_block_type_t functionBlockType,
90           function_block_type_t functionBlockId,
91           EPlugAddressType plugAddressType,
92           EPlugDirection plugDirection,
93           plug_id_t plugId );
94     Plug( Unit* unit,
95           Subunit* subunit,
96           function_block_type_t functionBlockType,
97           function_block_type_t functionBlockId,
98           EPlugAddressType plugAddressType,
99           EPlugDirection plugDirection,
100           plug_id_t plugId,
101           int globalId );
102     Plug( const Plug& rhs );
103     virtual ~Plug();
104
105     bool inquireConnnection( Plug& plug );
106     bool setConnection( Plug& plug );
107
108     int getSignalSource();
109
110     int getGlobalId() const
111         { return m_globalId; }
112     plug_id_t getPlugId() const
113         { return m_id; }
114     ESubunitType getSubunitType() const;
115     subunit_id_t getSubunitId() const;
116
117     const char* getName() const
118         { return m_name.c_str(); }
119     bool setName(const char *n)
120         { m_name=n; return true; }
121     bool setName(std::string n)
122         { m_name=n; return true; }
123     EPlugDirection getPlugDirection() const
124         { return m_direction; }
125     bool setPlugDirection(EPlugDirection d)
126         { m_direction=d; return true; }
127     sampling_frequency_t getSamplingFrequency() const
128         { return m_samplingFrequency; }
129     int getSampleRate() const; // 22050, 24000, 32000, ...
130     bool setSampleRate( int rate );
131     bool supportsSampleRate( int rate );
132
133     int getNrOfChannels() const;
134     bool setNrOfChannels(int i);
135     int getNrOfStreams() const;
136
137     // FIXME: this is the same as getPlugDirection
138     EPlugDirection getDirection() const
139         { return m_direction; }
140     EPlugAddressType getPlugAddressType() const
141         { return m_addressType; }
142     EPlugType getPlugType() const
143         { return m_infoPlugType; }
144     bool setPlugType(EPlugType t)
145         { m_infoPlugType=t; return true; }
146
147     function_block_type_t getFunctionBlockType() const
148         { return m_functionBlockType; }
149     function_block_id_t getFunctionBlockId() const
150         { return m_functionBlockId; }
151
152 //     const PlugVector& getInputConnections() const
153 //         { return m_inputConnections; }
154 //     const PlugVector& getOutputConnections() const
155 //         { return m_outputConnections; }
156     PlugVector& getInputConnections()
157         { return m_inputConnections; }
158     PlugVector& getOutputConnections()
159         { return m_outputConnections; }
160
161     static PlugAddress::EPlugDirection convertPlugDirection(
162     EPlugDirection direction);
163
164     void showPlug() const;
165
166     bool serialize( std::string basePath, Util::IOSerialize& ser ) const;
167     static Plug* deserialize( std::string basePath,
168                               Util::IODeserialize& deser,
169                               Unit& avDevice,
170                               PlugManager& plugManager );
171     bool deserializeConnections( std::string basePath,
172                                  Util::IODeserialize& deser );
173     bool deserializeUpdateSubunit();
174
175  public:
176     struct ChannelInfo {
177         stream_position_t          m_streamPosition;
178         stream_position_location_t m_location;
179         std::string              m_name;
180     };
181     typedef std::vector<ChannelInfo> ChannelInfoVector;
182
183     struct ClusterInfo {
184         int                 m_index;
185         port_type_t         m_portType;
186         std::string         m_name;
187
188         nr_of_channels_t    m_nrOfChannels;
189         ChannelInfoVector   m_channelInfos;
190         stream_format_t     m_streamFormat;
191     };
192     typedef std::vector<ClusterInfo> ClusterInfoVector;
193
194     ClusterInfoVector& getClusterInfos()
195         { return m_clusterInfos; }
196
197     virtual void setVerboseLevel( int i );
198
199 // the discovery interface
200 // everything can be overloaded, or
201 // can be left as is
202 public:
203     virtual bool discover();
204     virtual bool discoverConnections();
205     virtual bool propagateFromConnectedPlug( );
206
207 protected:
208     virtual bool discoverPlugType();
209     virtual bool discoverName();
210     virtual bool discoverNoOfChannels();
211     virtual bool discoverChannelPosition();
212     virtual bool discoverChannelName();
213     virtual bool discoverClusterInfo();
214     virtual bool discoverStreamFormat();
215     virtual bool discoverSupportedStreamFormats();
216     virtual bool discoverConnectionsInput();
217     virtual bool discoverConnectionsOutput();
218     virtual bool initFromDescriptor();
219
220     bool propagateFromPlug( Plug *p );
221
222     ExtendedStreamFormatCmd setPlugAddrToStreamFormatCmd(
223             ExtendedStreamFormatCmd::ESubFunction subFunction);
224
225 protected:
226     Plug();
227
228     SignalSourceCmd setSrcPlugAddrToSignalCmd();
229
230     void setDestPlugAddrToSignalCmd(
231             SignalSourceCmd& signalSourceCmd, Plug& plug );
232
233     void debugOutputClusterInfos( int debugLevel );
234
235     bool addPlugConnection( PlugVector& connections, Plug& plug );
236
237     bool discoverConnectionsFromSpecificData(
238         EPlugDirection discoverDirection,
239         PlugAddressSpecificData* plugAddress,
240         PlugVector& connections );
241
242     Plug* getPlugDefinedBySpecificData(
243         UnitPlugSpecificDataPlugAddress* pUnitPlugAddress,
244         SubunitPlugSpecificDataPlugAddress* pSubunitPlugAddress,
245         FunctionBlockPlugSpecificDataPlugAddress* pFunctionBlockPlugAddress );
246
247     EPlugDirection toggleDirection( EPlugDirection direction ) const;
248
249     const ClusterInfo* getClusterInfoByIndex( int index ) const;
250
251     bool serializeChannelInfos( std::string basePath,
252                                 Util::IOSerialize& ser,
253                                 const ClusterInfo& clusterInfo ) const;
254     bool deserializeChannelInfos( std::string basePath,
255                                   Util::IODeserialize& deser,
256                                   ClusterInfo& clusterInfo );
257
258     bool serializeClusterInfos( std::string basePath,
259                                 Util::IOSerialize& ser ) const;
260     bool deserializeClusterInfos( std::string basePath,
261                                   Util::IODeserialize& deser );
262
263     bool serializeFormatInfos( std::string basePath,
264                                Util::IOSerialize& ser ) const;
265     bool deserializeFormatInfos( std::string basePath,
266                                  Util::IODeserialize& deser );
267
268 protected:
269     // Supported stream formats
270     struct FormatInfo {
271         FormatInfo()
272             : m_samplingFrequency( eSF_DontCare )
273             , m_isSyncStream( false )
274             , m_audioChannels( 0 )
275             , m_midiChannels( 0 )
276             , m_index( 0xff )
277             {}
278         sampling_frequency_t  m_samplingFrequency;
279         bool                       m_isSyncStream;
280         number_of_channels_t  m_audioChannels;
281         number_of_channels_t  m_midiChannels;
282         byte_t                     m_index;
283     };
284     typedef std::vector<FormatInfo> FormatInfoVector;
285
286
287     Unit*                       m_unit;
288     Subunit*                    m_subunit;
289     ESubunitType                m_subunitType;
290     subunit_t                   m_subunitId;
291     function_block_type_t       m_functionBlockType;
292     function_block_id_t         m_functionBlockId;
293     EPlugAddressType            m_addressType;
294     EPlugDirection              m_direction;
295     plug_id_t                   m_id;
296     EPlugType                   m_infoPlugType;
297     nr_of_channels_t            m_nrOfChannels;
298     std::string                 m_name;
299     ClusterInfoVector           m_clusterInfos;
300     sampling_frequency_t        m_samplingFrequency;
301     FormatInfoVector            m_formatInfos;
302     PlugVector                  m_inputConnections;
303     PlugVector                  m_outputConnections;
304     int                         m_globalId;
305
306     DECLARE_DEBUG_MODULE;
307 };
308
309 const char* avPlugAddressTypeToString( Plug::EPlugAddressType addressType );
310 const char* avPlugTypeToString( Plug::EPlugType type );
311 const char* avPlugDirectionToString( Plug::EPlugDirection direction );
312
313 class PlugManager
314 {
315 public:
316     PlugManager( );
317     PlugManager( const PlugManager& rhs );
318     ~PlugManager();
319
320     bool addPlug( Plug& plug );
321     bool remPlug( Plug& plug );
322
323     void showPlugs() const;
324
325     int getPlugCount()
326         { return m_plugs.size(); };
327
328     int requestNewGlobalId()
329         { return m_globalIdCounter++; };
330
331     Plug* getPlug( ESubunitType subunitType,
332                    subunit_id_t subunitId,
333                    function_block_type_t functionBlockType,
334                    function_block_id_t functionBlockId,
335                    Plug::EPlugAddressType plugAddressType,
336                    Plug::EPlugDirection plugDirection,
337                    plug_id_t plugId ) const;
338     Plug* getPlug( int iGlobalId ) const;
339     PlugVector getPlugsByType( ESubunitType subunitType,
340                                subunit_id_t subunitId,
341                                function_block_type_t functionBlockType,
342                                function_block_id_t functionBlockId,
343                                Plug::EPlugAddressType plugAddressType,
344                                Plug::EPlugDirection plugDirection,
345                                Plug::EPlugType type) const;
346
347     bool serialize( std::string basePath, Util::IOSerialize& ser ) const;
348     static  PlugManager* deserialize( std::string basePath,
349                                       Util::IODeserialize& deser,
350                                       Unit& avDevice );
351     void setVerboseLevel( int i );
352     PlugVector& getPlugs()
353         { return m_plugs; }
354     bool tidyPlugConnections(PlugConnectionVector&);
355
356     bool deserializeUpdate( std::string basePath, 
357                             Util::IODeserialize& deser );
358
359 private:
360     int m_globalIdCounter;
361
362     PlugVector   m_plugs;
363
364     DECLARE_DEBUG_MODULE;
365 };
366
367 class PlugConnection {
368 public:
369     PlugConnection( Plug& srcPlug, Plug& destPlug );
370
371     Plug& getSrcPlug() const
372         { return *m_srcPlug; }
373     Plug& getDestPlug() const
374         { return *m_destPlug; }
375
376     bool serialize( std::string basePath, Util::IOSerialize& ser ) const;
377     static PlugConnection* deserialize( std::string basePath,
378                                         Util::IODeserialize& deser,
379                                         Unit& avDevice );
380 private:
381     PlugConnection();
382
383 private:
384     Plug* m_srcPlug;
385     Plug* m_destPlug;
386 };
387
388 typedef std::vector<PlugConnection> PlugConnectionOwnerVector;
389
390
391 bool serializePlugVector( std::string basePath,
392                           Util::IOSerialize& ser,
393                           const PlugVector& vec);
394
395 bool deserializePlugVector( std::string basePath,
396                             Util::IODeserialize& deser,
397                             const PlugManager& plugManager,
398                             PlugVector& vec );
399
400 }
401
402 #endif // AVC_PLUG
Note: See TracBrowser for help on using the browser.