root/trunk/libffado/src/bebob/bebob_avplug.h

Revision 435, 11.1 kB (checked in by pieterpalmers, 15 years ago)

src/devicemanager:
- start OSC server for the device manager

src/devicemanager,
src/iavdevice,
src/libieee1394/configrom:
- inherit from OscNode? to become Osc'able

src/bounce,
src/libstreaming/AmdtpStreamProcessor,
src/libstreaming/AmdtpSlaveStreamProcessor:
- fixed bounce device implementation, now working

src/bebob:
- fixed midi bug

General:
- removed 'intermediate XML'
- removed obsolete tests
- removed obsolete files
- removed obsolete API calls

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