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

Revision 524, 6.2 kB (checked in by ppalmers, 15 years ago)

echo discovery works, audio I/O works, still some issues with midi and channel naming

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    
128    
129     int idx=1;
130     for ( AVCMusicClusterInfoBlockVectorIterator it = info->m_Clusters.begin();
131       it != info->m_Clusters.end();
132       ++it )
133     {
134         struct Plug::ClusterInfo cinfo;
135        
136         AVCMusicClusterInfoBlock *c=(*it);
137        
138         cinfo.m_index=idx; //FIXME: is this correct?
139         cinfo.m_portType=c->m_port_type;
140         cinfo.m_nrOfChannels=c->m_nb_signals;
141         cinfo.m_streamFormat=c->m_stream_format;
142         cinfo.m_name=c->getName();
143
144         debugOutput(DEBUG_LEVEL_VERBOSE, "Adding cluster idx=%2d type=%02X nbch=%2d fmt=%02X name=%s\n",
145             cinfo.m_index, cinfo.m_portType, cinfo.m_nrOfChannels, cinfo.m_streamFormat, cinfo.m_name.c_str());
146
147         for ( AVCMusicClusterInfoBlock::SignalInfoVectorIterator sig_it
148               = c->m_SignalInfos.begin();
149             sig_it != c->m_SignalInfos.end();
150             ++sig_it )
151         {
152             struct AVCMusicClusterInfoBlock::sSignalInfo s=(*sig_it);
153             struct Plug::ChannelInfo sinfo;
154            
155             sinfo.m_streamPosition=s.stream_position;
156             sinfo.m_location=s.stream_location;
157            
158             AVCMusicPlugInfoBlock *mplug=m_status_descriptor->getMusicPlugInfoBlock(s.music_plug_id);
159            
160             if (mplug==NULL) {
161                 debugWarning("No music plug found for this signal\n");
162                 sinfo.m_name="unknown";
163             } else {
164                 sinfo.m_name=mplug->getName();
165             }
166            
167             debugOutput(DEBUG_LEVEL_VERBOSE, "Adding signal pos=%2d loc=%2d name=%s\n",
168                 sinfo.m_streamPosition, sinfo.m_location, mplug->getName().c_str());
169            
170             cinfo.m_channelInfos.push_back(sinfo);
171         }
172
173         idx++;
174         plug.getClusterInfos().push_back(cinfo);
175     }
176    
177    
178     return result;
179
180 }
181
182 bool
183 SubunitMusic::loadDescriptors()
184 {
185     bool result=true;
186     if (m_status_descriptor != NULL) {
187         result &= m_status_descriptor->load();
188     } else {
189         debugError("BUG: m_status_descriptor == NULL\n");
190         return false;
191     }
192     return result;
193 }
194
195 void SubunitMusic::setVerboseLevel(int l)
196 {
197     Subunit::setVerboseLevel(l);
198     if (m_status_descriptor != NULL) {
199         m_status_descriptor->setVerboseLevel(l);
200     }
201 }
202
203 const char*
204 SubunitMusic::getName()
205 {
206     return "MusicSubunit";
207 }
208
209 bool
210 SubunitMusic::serializeChild( Glib::ustring basePath,
211                                              Util::IOSerialize& ser ) const
212 {
213     return true;
214 }
215
216 bool
217 SubunitMusic::deserializeChild( Glib::ustring basePath,
218                                                Util::IODeserialize& deser,
219                                                Unit& unit )
220 {
221     return true;
222 }
223
224 }
Note: See TracBrowser for help on using the browser.