root/branches/echoaudio/src/bebob/bebob_avplug.h

Revision 503, 11.8 kB (checked in by ppalmers, 17 years ago)

- put all libavc stuff into it's own name namespace (AVC)

Line 
1 /*
2  * Copyright (C) 2005-2007 by Daniel Wagner
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
22  */
23
24 #ifndef BEBOB_AVPLUG_H
25 #define BEBOB_AVPLUG_H
26
27 #include "libavc/ccm/avc_signal_source.h"
28 #include "libavc/streamformat/avc_extended_stream_format.h"
29 #include "libavc/general/avc_extended_plug_info.h"
30 #include "libavc/general/avc_extended_cmd_generic.h"
31 #include "libavc/avc_definitions.h"
32 #include "libavc/general/avc_generic.h"
33
34 #include "libutil/serialize.h"
35
36 #include "debugmodule/debugmodule.h"
37
38 #include <glibmm/ustring.h>
39
40 #warning clean up the samplerate mess
41 #include "ffadodevice.h"
42
43 class Ieee1394Service;
44 class ConfigRom;
45
46 namespace BeBoB {
47
48 class AvDevice;
49 class AvPlugManager;
50 class AvPlug;
51
52 typedef std::vector<AvPlug*> AvPlugVector;
53
54 class AvPlug {
55 public:
56
57     enum EAvPlugAddressType {
58     eAPA_PCR,
59     eAPA_ExternalPlug,
60     eAPA_AsynchronousPlug,
61     eAPA_SubunitPlug,
62     eAPA_FunctionBlockPlug,
63     eAPA_Undefined,
64     };
65
66     enum EAvPlugType {
67         eAPT_IsoStream,
68         eAPT_AsyncStream,
69         eAPT_Midi,
70         eAPT_Sync,
71         eAPT_Analog,
72         eAPT_Digital,
73         eAPT_Unknown,
74     };
75
76     enum EAvPlugDirection {
77     eAPD_Input,
78     eAPD_Output,
79     eAPD_Unknown,
80     };
81
82     // \todo This constructors sucks. too many parameters. fix it.
83     AvPlug( Ieee1394Service& ieee1394Service,
84         ConfigRom& configRom,
85             AvPlugManager& plugManager,
86         AVC::ESubunitType subunitType,
87         AVC::subunit_id_t subunitId,
88         AVC::function_block_type_t functionBlockType,
89         AVC::function_block_type_t functionBlockId,
90         EAvPlugAddressType plugAddressType,
91         EAvPlugDirection plugDirection,
92         AVC::plug_id_t plugId,
93         int verboseLevel );
94     AvPlug( const AvPlug& rhs );
95     virtual ~AvPlug();
96
97     bool discover();
98     bool discoverConnections();
99
100     bool inquireConnnection( AvPlug& plug );
101     bool setConnection( AvPlug& plug );
102
103     int getGlobalId() const
104         { return m_globalId; }
105     AVC::plug_id_t getPlugId() const
106         { return m_id; }
107     AVC::ESubunitType getSubunitType() const
108         { return m_subunitType; }
109     AVC::subunit_id_t getSubunitId() const
110         { return m_subunitId; }
111     const char* getName() const
112         { return m_name.c_str(); }
113     EAvPlugDirection getPlugDirection() const
114         { return m_direction; }
115     AVC::sampling_frequency_t getSamplingFrequency() const
116         { return m_samplingFrequency; }
117     int getSampleRate() const; // 22050, 24000, 32000, ...
118     int getNrOfChannels() const;
119     int getNrOfStreams() const;
120
121     EAvPlugDirection getDirection() const
122         { return m_direction; }
123     EAvPlugAddressType getPlugAddressType() const
124         { return m_addressType; }
125     EAvPlugType getPlugType() const
126         { return m_infoPlugType; }
127
128     AVC::function_block_type_t getFunctionBlockType() const
129         { return m_functionBlockType; }
130     AVC::function_block_id_t getFunctionBlockId() const
131         { return m_functionBlockId; }
132
133     const AvPlugVector& getInputConnections() const
134         { return m_inputConnections; }
135     const AvPlugVector& getOutputConnections() const
136         { return m_outputConnections; }
137
138     static AVC::PlugAddress::EPlugDirection convertPlugDirection(
139     EAvPlugDirection direction);
140
141     void showPlug() const;
142
143     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const;
144     static AvPlug* deserialize( Glib::ustring basePath,
145                                 Util::IODeserialize& deser,
146                                 AvDevice& avDevice,
147                                 AvPlugManager& plugManager );
148
149     bool deserializeUpdate( Glib::ustring basePath,
150                             Util::IODeserialize& deser );
151
152  public:
153     struct ChannelInfo {
154         AVC::stream_position_t          m_streamPosition;
155         AVC::stream_position_location_t m_location;
156         Glib::ustring                   m_name;
157     };
158     typedef std::vector<ChannelInfo> ChannelInfoVector;
159
160     struct ClusterInfo {
161         int                      m_index;
162         AVC::port_type_t         m_portType;
163         Glib::ustring            m_name;
164
165         AVC::nr_of_channels_t    m_nrOfChannels;
166         ChannelInfoVector        m_channelInfos;
167         AVC::stream_format_t     m_streamFormat;
168     };
169     typedef std::vector<ClusterInfo> ClusterInfoVector;
170
171     ClusterInfoVector& getClusterInfos()
172         { return m_clusterInfos; }
173
174 protected:
175     AvPlug();
176
177     bool discoverPlugType();
178     bool discoverName();
179     bool discoverNoOfChannels();
180     bool discoverChannelPosition();
181     bool discoverChannelName();
182     bool discoverClusterInfo();
183     bool discoverStreamFormat();
184     bool discoverSupportedStreamFormats();
185     bool discoverConnectionsInput();
186     bool discoverConnectionsOutput();
187
188     AVC::ExtendedPlugInfoCmd setPlugAddrToPlugInfoCmd();
189
190     AVC::ExtendedStreamFormatCmd setPlugAddrToStreamFormatCmd(
191             AVC::ExtendedStreamFormatCmd::ESubFunction subFunction);
192
193     AVC::SignalSourceCmd setSrcPlugAddrToSignalCmd();
194
195     void setDestPlugAddrToSignalCmd(
196             AVC::SignalSourceCmd& signalSourceCmd, AvPlug& plug );
197
198     void debugOutputClusterInfos( int debugLevel );
199
200     bool copyClusterInfo(AVC::ExtendedPlugInfoPlugChannelPositionSpecificData&
201                          channelPositionData );
202
203     bool addPlugConnection( AvPlugVector& connections, AvPlug& plug );
204
205     bool discoverConnectionsFromSpecificData(
206         EAvPlugDirection discoverDirection,
207         AVC::PlugAddressSpecificData* plugAddress,
208         AvPlugVector& connections );
209
210     AvPlug* getPlugDefinedBySpecificData(
211         AVC::UnitPlugSpecificDataPlugAddress* pUnitPlugAddress,
212         AVC::SubunitPlugSpecificDataPlugAddress* pSubunitPlugAddress,
213         AVC::FunctionBlockPlugSpecificDataPlugAddress* pFunctionBlockPlugAddress );
214
215     EAvPlugDirection toggleDirection( EAvPlugDirection direction ) const;
216
217     const ClusterInfo* getClusterInfoByIndex( int index ) const;
218
219     bool serializeChannelInfos( Glib::ustring basePath,
220                                 Util::IOSerialize& ser,
221                                 const ClusterInfo& clusterInfo ) const;
222     bool deserializeChannelInfos( Glib::ustring basePath,
223                                   Util::IODeserialize& deser,
224                                   ClusterInfo& clusterInfo );
225
226     bool serializeClusterInfos( Glib::ustring basePath,
227                                 Util::IOSerialize& ser ) const;
228     bool deserializeClusterInfos( Glib::ustring basePath,
229                                   Util::IODeserialize& deser );
230
231     bool serializeFormatInfos( Glib::ustring basePath,
232                                Util::IOSerialize& ser ) const;
233     bool deserializeFormatInfos( Glib::ustring basePath,
234                                  Util::IODeserialize& deser );
235
236     bool serializeAvPlugVector( Glib::ustring basePath,
237                                 Util::IOSerialize& ser,
238                                 const AvPlugVector& vec) const;
239     bool deserializeAvPlugVector( Glib::ustring basePath,
240                                   Util::IODeserialize& deser,
241                                   AvPlugVector& vec );
242
243 private:
244     // Supported stream formats
245     struct FormatInfo {
246         FormatInfo()
247             : m_samplingFrequency( eSF_DontCare )
248             , m_isSyncStream( false )
249             , m_audioChannels( 0 )
250             , m_midiChannels( 0 )
251             , m_index( 0xff )
252             {}
253     AVC::sampling_frequency_t  m_samplingFrequency;
254     bool                       m_isSyncStream;
255     AVC::number_of_channels_t  m_audioChannels;
256     AVC::number_of_channels_t  m_midiChannels;
257     byte_t                     m_index;
258     };
259     typedef std::vector<FormatInfo> FormatInfoVector;
260
261
262     Ieee1394Service*             m_p1394Service;
263     ConfigRom*                   m_pConfigRom;
264     AVC::ESubunitType     m_subunitType;
265     AVC::subunit_id_t                 m_subunitId;
266     AVC::function_block_type_t        m_functionBlockType;
267     AVC::function_block_id_t          m_functionBlockId;
268     EAvPlugAddressType           m_addressType;
269     EAvPlugDirection             m_direction;
270     AVC::plug_id_t                    m_id;
271     EAvPlugType                  m_infoPlugType;
272     AVC::nr_of_channels_t             m_nrOfChannels;
273     Glib::ustring                m_name;
274     ClusterInfoVector            m_clusterInfos;
275     AVC::sampling_frequency_t         m_samplingFrequency;
276     FormatInfoVector             m_formatInfos;
277     AvPlugVector                 m_inputConnections;
278     AvPlugVector                 m_outputConnections;
279     AvPlugManager*               m_plugManager;
280     int                          m_verboseLevel;
281     int                          m_globalId;
282     static int                   m_globalIdCounter;
283
284     DECLARE_DEBUG_MODULE;
285 };
286
287 const char* avPlugAddressTypeToString( AvPlug::EAvPlugAddressType addressType );
288 const char* avPlugTypeToString( AvPlug::EAvPlugType type );
289 const char* avPlugDirectionToString( AvPlug::EAvPlugDirection direction );
290
291 class AvPlugManager
292 {
293 public:
294     AvPlugManager( int verboseLevel );
295     AvPlugManager( const AvPlugManager& rhs );
296     ~AvPlugManager();
297
298     bool addPlug( AvPlug& plug );
299     bool remPlug( AvPlug& plug );
300
301     void showPlugs() const;
302
303     AvPlug* getPlug( AVC::ESubunitType subunitType,
304                      AVC::subunit_id_t subunitId,
305                      AVC::function_block_type_t functionBlockType,
306                      AVC::function_block_id_t functionBlockId,
307                      AvPlug::EAvPlugAddressType plugAddressType,
308                      AvPlug::EAvPlugDirection plugDirection,
309                      AVC::plug_id_t plugId ) const;
310     AvPlug* getPlug( int iGlobalId ) const;
311     AvPlugVector getPlugsByType( AVC::ESubunitType subunitType,
312                  AVC::subunit_id_t subunitId,
313                  AVC::function_block_type_t functionBlockType,
314                  AVC::function_block_id_t functionBlockId,
315                  AvPlug::EAvPlugAddressType plugAddressType,
316                  AvPlug::EAvPlugDirection plugDirection,
317                  AvPlug::EAvPlugType type) const;
318
319     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const;
320     static  AvPlugManager* deserialize( Glib::ustring basePath,
321                                         Util::IODeserialize& deser,
322                                         AvDevice& avDevice );
323
324 private:
325     AvPlugManager();
326
327     int          m_verboseLevel;
328     AvPlugVector m_plugs;
329
330     DECLARE_DEBUG_MODULE;
331 };
332
333 class AvPlugConnection {
334 public:
335     AvPlugConnection( AvPlug& srcPlug, AvPlug& destPlug );
336
337     AvPlug& getSrcPlug() const
338         { return *m_srcPlug; }
339     AvPlug& getDestPlug() const
340         { return *m_destPlug; }
341
342     bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const;
343     static AvPlugConnection* deserialize( Glib::ustring basePath,
344                                           Util::IODeserialize& deser,
345                                           AvDevice& avDevice );
346 private:
347     AvPlugConnection();
348
349 private:
350     AvPlug* m_srcPlug;
351     AvPlug* m_destPlug;
352 };
353
354 typedef std::vector<AvPlugConnection*> AvPlugConnectionVector;
355 typedef std::vector<AvPlugConnection> AvPlugConnectionOwnerVector;
356
357 }
358
359 #endif // BEBOB_AVPLUG_H
Note: See TracBrowser for help on using the browser.