root/branches/echoaudio/src/libavc/general/avc_plug.h

Revision 548, 12.0 kB (checked in by ppalmers, 15 years ago)

- make the BeBoB AvDevice? a child class of the GenericAVC AvDevice?. This
avoids a lot of code duplication.
- fix inconsistency in position/location numbering between ext pluginfo
cmd and descriptor.

Line 
1 /*
2  * Copyright (C)      2007 by Pieter Palmers
3  * Copyright (C) 2005-2007 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 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 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 <glibmm/ustring.h>
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( const Plug& rhs );
95     virtual ~Plug();
96
97     bool inquireConnnection( Plug& plug );
98     bool setConnection( Plug& plug );
99
100     int getSignalSource();
101
102     int getGlobalId() const
103         { return m_globalId; }
104     plug_id_t getPlugId() const
105         { return m_id; }
106     ESubunitType getSubunitType() const;
107     subunit_id_t getSubunitId() const;
108    
109     const char* getName() const
110         { return m_name.c_str(); }
111     bool setName(const char *n)
112         { m_name=n; return true;};
113     bool setName(std::string n)
114         { m_name=n; return true;};
115     EPlugDirection getPlugDirection() const
116         { return m_direction; }
117     bool setPlugDirection(EPlugDirection d)
118         { m_direction=d; return true; }
119     sampling_frequency_t getSamplingFrequency() const
120         { return m_samplingFrequency; }
121     int getSampleRate() const; // 22050, 24000, 32000, ...
122     bool setSampleRate( int rate );
123    
124     int getNrOfChannels() const;
125     bool setNrOfChannels(int i);
126     int getNrOfStreams() const;
127
128     // FIXME: this is the same as getPlugDirection
129     EPlugDirection getDirection() const
130         { return m_direction; }
131     EPlugAddressType getPlugAddressType() const
132         { return m_addressType; }
133     EPlugType getPlugType() const
134         { return m_infoPlugType; }
135     bool setPlugType(EPlugType t)
136         { m_infoPlugType=t; return true; }
137
138     function_block_type_t getFunctionBlockType() const
139         { return m_functionBlockType; }
140     function_block_id_t getFunctionBlockId() const
141         { return m_functionBlockId; }
142
143 //     const PlugVector& getInputConnections() const
144 //         { return m_inputConnections; }
145 //     const PlugVector& getOutputConnections() const
146 //         { return m_outputConnections; }
147     PlugVector& getInputConnections()
148         { return m_inputConnections; }
149     PlugVector& getOutputConnections()
150         { return m_outputConnections; }
151
152     static PlugAddress::EPlugDirection convertPlugDirection(
153     EPlugDirection direction);
154
155     void showPlug() const;
156
157     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const;
158     static Plug* deserialize( Glib::ustring basePath,
159                                 Util::IODeserialize& deser,
160                                 Unit& avDevice,
161                                 PlugManager& plugManager );
162
163     bool deserializeUpdate( Glib::ustring basePath,
164                             Util::IODeserialize& deser );
165
166  public:
167     struct ChannelInfo {
168         stream_position_t          m_streamPosition;
169         stream_position_location_t m_location;
170         Glib::ustring              m_name;
171     };
172     typedef std::vector<ChannelInfo> ChannelInfoVector;
173
174     struct ClusterInfo {
175         int                 m_index;
176         port_type_t         m_portType;
177         Glib::ustring       m_name;
178
179         nr_of_channels_t    m_nrOfChannels;
180         ChannelInfoVector   m_channelInfos;
181         stream_format_t     m_streamFormat;
182     };
183     typedef std::vector<ClusterInfo> ClusterInfoVector;
184
185     ClusterInfoVector& getClusterInfos()
186         { return m_clusterInfos; }
187        
188     virtual void setVerboseLevel( int i )
189             {setDebugLevel(i);};
190    
191 // the discovery interface
192 // everything can be overloaded, or
193 // can be left as is
194 public:
195     virtual bool discover();
196     virtual bool discoverConnections();
197     virtual bool propagateFromConnectedPlug( );
198    
199 protected:
200     virtual bool discoverPlugType();
201     virtual bool discoverName();
202     virtual bool discoverNoOfChannels();
203     virtual bool discoverChannelPosition();
204     virtual bool discoverChannelName();
205     virtual bool discoverClusterInfo();
206     virtual bool discoverStreamFormat();
207     virtual bool discoverSupportedStreamFormats();
208     virtual bool discoverConnectionsInput();
209     virtual bool discoverConnectionsOutput();
210     virtual bool initFromDescriptor();
211
212     bool propagateFromPlug( Plug *p );
213
214     ExtendedStreamFormatCmd setPlugAddrToStreamFormatCmd(
215             ExtendedStreamFormatCmd::ESubFunction subFunction);
216
217 protected:
218     Plug();
219
220     SignalSourceCmd setSrcPlugAddrToSignalCmd();
221
222     void setDestPlugAddrToSignalCmd(
223             SignalSourceCmd& signalSourceCmd, Plug& plug );
224
225     void debugOutputClusterInfos( int debugLevel );
226
227     bool addPlugConnection( PlugVector& connections, Plug& plug );
228
229     bool discoverConnectionsFromSpecificData(
230         EPlugDirection discoverDirection,
231         PlugAddressSpecificData* plugAddress,
232         PlugVector& connections );
233
234     Plug* getPlugDefinedBySpecificData(
235         UnitPlugSpecificDataPlugAddress* pUnitPlugAddress,
236         SubunitPlugSpecificDataPlugAddress* pSubunitPlugAddress,
237         FunctionBlockPlugSpecificDataPlugAddress* pFunctionBlockPlugAddress );
238
239     EPlugDirection toggleDirection( EPlugDirection direction ) const;
240
241     const ClusterInfo* getClusterInfoByIndex( int index ) const;
242
243     bool serializeChannelInfos( Glib::ustring basePath,
244                                 Util::IOSerialize& ser,
245                                 const ClusterInfo& clusterInfo ) const;
246     bool deserializeChannelInfos( Glib::ustring basePath,
247                                   Util::IODeserialize& deser,
248                                   ClusterInfo& clusterInfo );
249
250     bool serializeClusterInfos( Glib::ustring basePath,
251                                 Util::IOSerialize& ser ) const;
252     bool deserializeClusterInfos( Glib::ustring basePath,
253                                   Util::IODeserialize& deser );
254
255     bool serializeFormatInfos( Glib::ustring basePath,
256                                Util::IOSerialize& ser ) const;
257     bool deserializeFormatInfos( Glib::ustring basePath,
258                                  Util::IODeserialize& deser );
259
260     bool serializePlugVector( Glib::ustring basePath,
261                                 Util::IOSerialize& ser,
262                                 const PlugVector& vec) const;
263     bool deserializePlugVector( Glib::ustring basePath,
264                                   Util::IODeserialize& deser,
265                                   PlugVector& vec );
266
267 protected:
268     // Supported stream formats
269     struct FormatInfo {
270         FormatInfo()
271             : m_samplingFrequency( eSF_DontCare )
272             , m_isSyncStream( false )
273             , m_audioChannels( 0 )
274             , m_midiChannels( 0 )
275             , m_index( 0xff )
276             {}
277         sampling_frequency_t  m_samplingFrequency;
278         bool                       m_isSyncStream;
279         number_of_channels_t  m_audioChannels;
280         number_of_channels_t  m_midiChannels;
281         byte_t                     m_index;
282     };
283     typedef std::vector<FormatInfo> FormatInfoVector;
284
285
286     Unit*                       m_unit;
287     Subunit*                    m_subunit;
288     function_block_type_t       m_functionBlockType;
289     function_block_id_t         m_functionBlockId;
290     EPlugAddressType            m_addressType;
291     EPlugDirection              m_direction;
292     plug_id_t                   m_id;
293     EPlugType                   m_infoPlugType;
294     nr_of_channels_t            m_nrOfChannels;
295     Glib::ustring               m_name;
296     ClusterInfoVector           m_clusterInfos;
297     sampling_frequency_t        m_samplingFrequency;
298     FormatInfoVector            m_formatInfos;
299     PlugVector                  m_inputConnections;
300     PlugVector                  m_outputConnections;
301     int                         m_globalId;
302     static int                  m_globalIdCounter;
303
304     DECLARE_DEBUG_MODULE;
305 };
306
307 const char* avPlugAddressTypeToString( Plug::EPlugAddressType addressType );
308 const char* avPlugTypeToString( Plug::EPlugType type );
309 const char* avPlugDirectionToString( Plug::EPlugDirection direction );
310
311 class PlugManager
312 {
313 public:
314     PlugManager( );
315     PlugManager( const PlugManager& rhs );
316     ~PlugManager();
317
318     bool addPlug( Plug& plug );
319     bool remPlug( Plug& plug );
320
321     void showPlugs() const;
322
323     int getPlugCount()
324         { return m_plugs.size(); };
325
326     Plug* getPlug( ESubunitType subunitType,
327                    subunit_id_t subunitId,
328                    function_block_type_t functionBlockType,
329                    function_block_id_t functionBlockId,
330                    Plug::EPlugAddressType plugAddressType,
331                    Plug::EPlugDirection plugDirection,
332                    plug_id_t plugId ) const;
333     Plug* getPlug( int iGlobalId ) const;
334     PlugVector getPlugsByType( ESubunitType subunitType,
335                  subunit_id_t subunitId,
336                  function_block_type_t functionBlockType,
337                  function_block_id_t functionBlockId,
338                  Plug::EPlugAddressType plugAddressType,
339                  Plug::EPlugDirection plugDirection,
340                  Plug::EPlugType type) const;
341
342     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const;
343     static  PlugManager* deserialize( Glib::ustring basePath,
344                                         Util::IODeserialize& deser,
345                                         Unit& avDevice );
346     void setVerboseLevel( int i )
347             {setDebugLevel(i);};
348     PlugVector& getPlugs() {return m_plugs;};
349     bool tidyPlugConnections(PlugConnectionVector&);
350
351 private:
352
353     PlugVector   m_plugs;
354
355     DECLARE_DEBUG_MODULE;
356 };
357
358 class PlugConnection {
359 public:
360     PlugConnection( Plug& srcPlug, Plug& destPlug );
361
362     Plug& getSrcPlug() const
363         { return *m_srcPlug; }
364     Plug& getDestPlug() const
365         { return *m_destPlug; }
366
367     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const;
368     static PlugConnection* deserialize( Glib::ustring basePath,
369                                           Util::IODeserialize& deser,
370                                           Unit& avDevice );
371 private:
372     PlugConnection();
373
374 private:
375     Plug* m_srcPlug;
376     Plug* m_destPlug;
377 };
378
379 typedef std::vector<PlugConnection> PlugConnectionOwnerVector;
380
381 }
382
383 #endif // AVC_PLUG
Note: See TracBrowser for help on using the browser.