root/trunk/libffado/src/libavc/musicsubunit/avc_musicsubunit.cpp

Revision 864, 8.0 kB (checked in by ppalmers, 15 years ago)

update license to GPLv2 or GPLv3 instead of GPLv2 or any later version. Update copyrights to reflect the new year

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