root/trunk/libffado/src/libstreaming/PortManager.cpp

Revision 554, 5.7 kB (checked in by ppalmers, 15 years ago)

Merge echoaudio branch into trunk.

This adds support for the Echo Audiofire devices to FFADO. Possibly also other devices working with the Apple Class Driver will work with this code. It is not fully complete yet, but the main rework is
done.

First of all the IAvDevice class/interface is renamed to FFADODevice, in order to separate the AV/C code from the FFADO API code. A device supported by FFADO implements a FFADODevice.

The BeBoB device has been split up into three groups:
- libavc/* : all code and commands that are specified by AV/C specs. Note that a lot of the code that used to be in BeBoB::AvDevice? now resides in AVC::Unit
- genericavc/* : a FFADODevice that uses AV/C descriptors & commands for discovery and config
- bebob/* : the bebob FFADODevice that inherits from GenericAVC::AvDevice? but that uses BridgeCo? commands for discovery

Everything has been moved as high as possible in the class hierarchy. If necessary, a subclass that uses device specific commands is introduced (e.g. BeBoB::Plug inherits from AVC::Plug and uses the
BridgeCo? extended plug info command to discover it's properties).

There are some other fixes along the way that have been done too.

Line 
1 /*
2  * Copyright (C) 2005-2007 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
22  */
23
24 #include "PortManager.h"
25 #include "Port.h"
26 #include <assert.h>
27
28 #include <iostream>
29 #include <sstream>
30
31
32 namespace Streaming {
33
34 IMPL_DEBUG_MODULE( PortManager, PortManager, DEBUG_LEVEL_NORMAL );
35
36 PortManager::PortManager() {
37
38 }
39
40 PortManager::~PortManager() {
41 //     deleteAllPorts();
42 }
43
44 // bool PortManager::setPortBuffersize(unsigned int newsize) {
45 //     debugOutput( DEBUG_LEVEL_VERBOSE, "setting port buffer size to %d\n",newsize);
46 //
47 //
48 //     for ( PortVectorIterator it = m_Ports.begin();
49 //       it != m_Ports.end();
50 //       ++it )
51 //     {
52 //         if(!(*it)->setBufferSize(newsize)) {
53 //             debugFatal("Could not set buffer size for port %s\n",(*it)->getName().c_str());
54 //             return false;
55 //         }
56 //     }
57 //
58 //     return true; //not found
59 //
60 // }
61
62 bool PortManager::makeNameUnique(Port *port)
63 {
64     bool done=false;
65     int idx=0;
66     std::string portname_orig=port->getName();
67    
68     while(!done && idx<10000) {
69         bool is_unique=true;
70        
71         for ( PortVectorIterator it = m_Ports.begin();
72         it != m_Ports.end();
73         ++it )
74         {
75             is_unique &= !((*it)->getName() == port->getName());
76         }
77        
78         if (is_unique) {
79             done=true;
80         } else {
81             std::ostringstream portname;
82             portname << portname_orig << idx++;
83            
84             port->setName(portname.str());
85         }
86     }
87    
88     if(idx<10000) return true;
89     else return false;
90 }
91
92 /**
93  *
94  * @param port
95  * @return
96  */
97 bool PortManager::addPort(Port *port)
98 {
99     assert(port);
100
101     debugOutput( DEBUG_LEVEL_VERBOSE, "Adding port %s, type: %d, dir: %d, dtype: %d\n",
102         port->getName().c_str(), port->getPortType(), port->getDirection(), port->getDataType());
103    
104     if (makeNameUnique(port)) {
105         m_Ports.push_back(port);
106         return true;
107     } else {
108         return false;
109     }
110 }
111
112 bool PortManager::deletePort(Port *port)
113 {
114     assert(port);
115     debugOutput( DEBUG_LEVEL_VERBOSE, "deleting port %s\n",port->getName().c_str());
116
117     for ( PortVectorIterator it = m_Ports.begin();
118       it != m_Ports.end();
119       ++it )
120     {
121         if(*it == port) {
122             m_Ports.erase(it);
123 //             delete *it;
124             return true;
125         }
126     }
127
128     debugOutput( DEBUG_LEVEL_VERBOSE, "port %s not found \n",port->getName().c_str());
129
130     return false; //not found
131
132 }
133
134 void PortManager::deleteAllPorts()
135 {
136     debugOutput( DEBUG_LEVEL_VERBOSE, "deleting all ports\n");
137
138     for ( PortVectorIterator it = m_Ports.begin();
139       it != m_Ports.end();
140       ++it )
141     {
142         m_Ports.erase(it);
143 //         delete *it;
144     }
145
146     return;
147
148 }
149
150 int PortManager::getPortCount(enum Port::E_PortType type) {
151     int count=0;
152
153     for ( PortVectorIterator it = m_Ports.begin();
154       it != m_Ports.end();
155       ++it )
156     {
157         if ( (*it)->getPortType() == type ) {
158             count++;
159         }
160     }
161     return count;
162 }
163
164 int PortManager::getPortCount() {
165     int count=0;
166
167     count+=m_Ports.size();
168
169     return count;
170 }
171
172 Port * PortManager::getPortAtIdx(unsigned int index) {
173
174     return m_Ports.at(index);
175
176 }
177
178 void PortManager::setVerboseLevel(int i) {
179
180     setDebugLevel(i);
181
182     for ( PortVectorIterator it = m_Ports.begin();
183       it != m_Ports.end();
184       ++it )
185     {
186         (*it)->setVerboseLevel(i);
187     }
188
189 }
190
191
192 bool PortManager::resetPorts() {
193     debugOutput( DEBUG_LEVEL_VERBOSE, "reset ports\n");
194
195     for ( PortVectorIterator it = m_Ports.begin();
196       it != m_Ports.end();
197       ++it )
198     {
199         if(!(*it)->reset()) {
200             debugFatal("Could not reset port %s",(*it)->getName().c_str());
201             return false;
202         }
203     }
204     return true;
205 }
206
207 bool PortManager::initPorts() {
208     debugOutput( DEBUG_LEVEL_VERBOSE, "init ports\n");
209
210     for ( PortVectorIterator it = m_Ports.begin();
211       it != m_Ports.end();
212       ++it )
213     {
214         if(!(*it)->init()) {
215             debugFatal("Could not init port %s",(*it)->getName().c_str());
216             return false;
217         }
218     }
219     return true;
220 }
221
222 bool PortManager::preparePorts() {
223     debugOutput( DEBUG_LEVEL_VERBOSE, "preparing ports\n");
224
225     // clear the cache lists
226     m_PeriodPorts.clear();
227     m_PacketPorts.clear();
228
229     for ( PortVectorIterator it = m_Ports.begin();
230       it != m_Ports.end();
231       ++it )
232     {
233         if(!(*it)->prepare()) {
234             debugFatal("Could not prepare port %s",(*it)->getName().c_str());
235             return false;
236         }
237
238         // now prepare the cache lists
239         switch((*it)->getSignalType()) {
240             case Port::E_PacketSignalled:
241                 m_PacketPorts.push_back(*it);
242                 break;
243             case Port::E_PeriodSignalled:
244                 m_PeriodPorts.push_back(*it);
245                 break;
246             default:
247                 debugWarning("%s has unsupported port type\n",
248                              (*it)->getName().c_str());
249             break;
250         }
251     }
252
253
254
255     return true;
256 }
257
258 }
Note: See TracBrowser for help on using the browser.