root/branches/echoaudio/src/libavc/musicsubunit/avc_musicsubunit.cpp

Revision 548, 8.3 kB (checked in by ppalmers, 15 years ago)

- make the BeBoB AvDevice? a child class of the GenericAVC AvDevice?. This
avoids a lot of code duplication.
- fix inconsistency in position/location numbering between ext pluginfo
cmd and descriptor.

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 #warning this header should go
26 #include "bebob/bebob_avplug.h"
27 #include "libieee1394/configrom.h"
28
29 #include "../general/avc_subunit.h"
30 #include "../general/avc_unit.h"
31
32 #include "../general/avc_plug_info.h"
33 #include "../streamformat/avc_extended_stream_format.h"
34 #include "../util/avc_serialize.h"
35
36 #include "avc_musicsubunit.h"
37 #include "avc_descriptor_music.h"
38
39 #include <sstream>
40
41 namespace AVC {
42
43 ////////////////////////////////////////////
44
45 SubunitMusic::SubunitMusic( Unit& unit, subunit_t id )
46     : Subunit( unit, eST_Music, id )
47     , m_status_descriptor ( new AVCMusicStatusDescriptor( &unit, this ) )
48 {
49
50 }
51
52 SubunitMusic::SubunitMusic()
53     : Subunit()
54     , m_status_descriptor ( NULL )
55 {
56 }
57
58 SubunitMusic::~SubunitMusic()
59 {
60     if (m_status_descriptor) delete m_status_descriptor;
61 }
62
63 bool
64 SubunitMusic::discover()
65 {
66     debugOutput(DEBUG_LEVEL_NORMAL, "Discovering %s...\n", getName());
67    
68     // discover the AV/C generic part
69     if ( !Subunit::discover() ) {
70         return false;
71     }
72    
73     // now we have the subunit plugs
74    
75     return true;
76 }
77
78 bool
79 SubunitMusic::initPlugFromDescriptor( Plug& plug )
80 {
81     debugOutput(DEBUG_LEVEL_VERBOSE, "Loading info from descriptor for plug: \n");
82     bool result=true;
83    
84     // load the descriptor (if not already loaded)
85     if (m_status_descriptor != NULL) {
86         result &= m_status_descriptor->load();
87     }
88    
89     AVCMusicSubunitPlugInfoBlock *info;
90     info = m_status_descriptor->getSubunitPlugInfoBlock(plug.getDirection(), plug.getPlugId());
91    
92     if (info == NULL) {
93         debugError("Could not find plug info block\n");
94         return false;
95     }
96    
97     debugOutput(DEBUG_LEVEL_VERBOSE, "Found plug: %s\n",info->getName().c_str());
98    
99     // plug name
100     result &= plug.setName(info->getName());
101    
102     // plug type
103     switch (info->m_plug_type) {
104         case AVCMusicSubunitPlugInfoBlock::ePT_IsoStream:
105             result &= plug.setPlugType(Plug::eAPT_IsoStream);
106             break;
107         case AVCMusicSubunitPlugInfoBlock::ePT_AsyncStream:
108             result &= plug.setPlugType(Plug::eAPT_AsyncStream);
109             break;
110         case AVCMusicSubunitPlugInfoBlock::ePT_Midi:
111             result &= plug.setPlugType(Plug::eAPT_Midi);
112             break;
113         case AVCMusicSubunitPlugInfoBlock::ePT_Sync:
114             result &= plug.setPlugType(Plug::eAPT_Sync);
115             break;
116         case AVCMusicSubunitPlugInfoBlock::ePT_Analog:
117             result &= plug.setPlugType(Plug::eAPT_Analog);
118             break;
119         case AVCMusicSubunitPlugInfoBlock::ePT_Digital:
120             result &= plug.setPlugType(Plug::eAPT_Digital);
121             break;
122     }
123    
124     // number of channels
125     result &= plug.setNrOfChannels(info->m_nb_channels);
126    
127     int idx=1;
128     for ( AVCMusicClusterInfoBlockVectorIterator it = info->m_Clusters.begin();
129       it != info->m_Clusters.end();
130       ++it )
131     {
132         struct Plug::ClusterInfo cinfo;
133        
134         AVCMusicClusterInfoBlock *c=(*it);
135        
136         cinfo.m_index=idx; //FIXME: is this correct?
137         cinfo.m_portType=c->m_port_type;
138         cinfo.m_nrOfChannels=c->m_nb_signals;
139         cinfo.m_streamFormat=c->m_stream_format;
140         cinfo.m_name=c->getName();
141
142         debugOutput(DEBUG_LEVEL_VERBOSE, "Adding cluster idx=%2d type=%02X nbch=%2d fmt=%02X name=%s\n",
143             cinfo.m_index, cinfo.m_portType, cinfo.m_nrOfChannels, cinfo.m_streamFormat, cinfo.m_name.c_str());
144
145         for ( AVCMusicClusterInfoBlock::SignalInfoVectorIterator sig_it
146               = c->m_SignalInfos.begin();
147             sig_it != c->m_SignalInfos.end();
148             ++sig_it )
149         {
150             struct AVCMusicClusterInfoBlock::sSignalInfo s=(*sig_it);
151             struct Plug::ChannelInfo sinfo;
152            
153             sinfo.m_streamPosition=s.stream_position;
154             sinfo.m_location=s.stream_location;
155            
156             AVCMusicPlugInfoBlock *mplug=m_status_descriptor->getMusicPlugInfoBlock(s.music_plug_id);
157            
158             if (mplug==NULL) {
159                 debugWarning("No music plug found for this signal\n");
160                 sinfo.m_name="unknown";
161             } else {
162                 sinfo.m_name=mplug->getName();
163             }
164            
165             if (plug.getDirection() == Plug::eAPD_Input) {
166                 // it's an input plug to the subunit
167                 // so we have to check the source field of the music plug
168                 if(s.stream_position != mplug->m_source_stream_position) {
169                     debugWarning("s.stream_position (= 0x%02X) != mplug->m_source_stream_position (= 0x%02X)\n",
170                         s.stream_position, mplug->m_source_stream_position);
171                     // use the one from the music plug
172                     sinfo.m_streamPosition= mplug->m_source_stream_position;
173                 }
174                 if(s.stream_location != mplug->m_source_stream_location) {
175                     debugWarning("s.stream_location (= 0x%02X) != mplug->m_source_stream_location (= 0x%02X)\n",
176                         s.stream_location, mplug->m_source_stream_location);
177                     // use the one from the music plug
178                     sinfo.m_location=mplug->m_source_stream_location;
179                 }
180             } else if (plug.getDirection() == Plug::eAPD_Output) {
181                 // it's an output plug from the subunit
182                 // so we have to check the destination field of the music plug
183                 if(s.stream_position != mplug->m_dest_stream_position) {
184                     debugWarning("s.stream_position (= 0x%02X) != mplug->m_dest_stream_position (= 0x%02X)\n",
185                         s.stream_position, mplug->m_dest_stream_position);
186                     // use the one from the music plug
187                     sinfo.m_streamPosition=mplug->m_dest_stream_position;
188                 }
189                 if(s.stream_location != mplug->m_dest_stream_location) {
190                     debugWarning("s.stream_location (= 0x%02X) != mplug->m_dest_stream_location (= 0x%02X)\n",
191                         s.stream_location, mplug->m_dest_stream_location);
192                     // use the one from the music plug
193                     sinfo.m_location=mplug->m_dest_stream_location;
194                 }
195             } else {
196                 debugWarning("Invalid plug direction.\n");
197             }
198            
199             debugOutput(DEBUG_LEVEL_VERBOSE, "Adding signal pos=%2d loc=%2d name=%s\n",
200                 sinfo.m_streamPosition, sinfo.m_location, mplug->getName().c_str());
201            
202             cinfo.m_channelInfos.push_back(sinfo);
203         }
204
205         idx++;
206         plug.getClusterInfos().push_back(cinfo);
207     }
208    
209    
210     return result;
211
212 }
213
214 bool
215 SubunitMusic::loadDescriptors()
216 {
217     bool result=true;
218     if (m_status_descriptor != NULL) {
219         result &= m_status_descriptor->load();
220     } else {
221         debugError("BUG: m_status_descriptor == NULL\n");
222         return false;
223     }
224     return result;
225 }
226
227 void SubunitMusic::setVerboseLevel(int l)
228 {
229     Subunit::setVerboseLevel(l);
230     if (m_status_descriptor != NULL) {
231         m_status_descriptor->setVerboseLevel(l);
232     }
233 }
234
235 const char*
236 SubunitMusic::getName()
237 {
238     return "MusicSubunit";
239 }
240
241 bool
242 SubunitMusic::serializeChild( Glib::ustring basePath,
243                                              Util::IOSerialize& ser ) const
244 {
245     return true;
246 }
247
248 bool
249 SubunitMusic::deserializeChild( Glib::ustring basePath,
250                                                Util::IODeserialize& deser,
251                                                Unit& unit )
252 {
253     return true;
254 }
255
256 }
Note: See TracBrowser for help on using the browser.