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

Revision 524, 12.3 kB (checked in by ppalmers, 15 years ago)

echo discovery works, audio I/O works, still some issues with midi and channel naming

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