root/branches/streaming-rework/src/bebob/bebob_avplug.h

Revision 420, 11.3 kB (checked in by pieterpalmers, 17 years ago)

moved src/libfreebobavc to src/libavc

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