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

Revision 185, 9.0 kB (checked in by wagi, 18 years ago)

CVS-SVN migration developer public sync patch

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