1 |
/* |
---|
2 |
* Copyright (C) 2005-2008 by Daniel Wagner |
---|
3 |
* Copyright (C) 2005-2008 by Pieter Palmers |
---|
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 "ffadodevice.h" |
---|
26 |
#include "devicemanager.h" |
---|
27 |
|
---|
28 |
#include "libieee1394/configrom.h" |
---|
29 |
#include "libieee1394/ieee1394service.h" |
---|
30 |
|
---|
31 |
#include "libcontrol/Element.h" |
---|
32 |
#include "libcontrol/ClockSelect.h" |
---|
33 |
#include "libcontrol/Nickname.h" |
---|
34 |
|
---|
35 |
#include <iostream> |
---|
36 |
#include <sstream> |
---|
37 |
#include <unistd.h> |
---|
38 |
|
---|
39 |
#include <assert.h> |
---|
40 |
|
---|
41 |
IMPL_DEBUG_MODULE( FFADODevice, FFADODevice, DEBUG_LEVEL_NORMAL ); |
---|
42 |
|
---|
43 |
FFADODevice::FFADODevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ) ) |
---|
44 |
: Control::Container(&d) |
---|
45 |
, m_pConfigRom( configRom ) |
---|
46 |
, m_pDeviceManager( d ) |
---|
47 |
{ |
---|
48 |
addOption(Util::OptionContainer::Option("id",m_pConfigRom->getGuidString())); |
---|
49 |
|
---|
50 |
std::ostringstream nodestr; |
---|
51 |
nodestr << "node" << getConfigRom().getNodeId(); |
---|
52 |
|
---|
53 |
if (!addElement(&getConfigRom())) { |
---|
54 |
debugWarning("failed to add ConfigRom to Control::Container\n"); |
---|
55 |
} |
---|
56 |
|
---|
57 |
m_genericContainer = new Control::Container(this, "Generic"); |
---|
58 |
if(m_genericContainer == NULL) { |
---|
59 |
debugError("Could not create Control::Container for generic controls\n"); |
---|
60 |
} else { |
---|
61 |
|
---|
62 |
if (!addElement(m_genericContainer)) { |
---|
63 |
debugWarning("failed to add generic container to Control::Container\n"); |
---|
64 |
} |
---|
65 |
// add a generic control for the clock source selection |
---|
66 |
if(!m_genericContainer->addElement(new Control::ClockSelect(*this))) { |
---|
67 |
debugWarning("failed to add clock source control to container\n"); |
---|
68 |
} |
---|
69 |
// add a generic control for the sample rate selection |
---|
70 |
if(!m_genericContainer->addElement(new Control::SamplerateSelect(*this))) { |
---|
71 |
debugWarning("failed to add sample rate control to container\n"); |
---|
72 |
} |
---|
73 |
// add a generic control for the nickname |
---|
74 |
if(!m_genericContainer->addElement(new Control::Nickname(*this))) { |
---|
75 |
debugWarning("failed to add Nickname control to container\n"); |
---|
76 |
} |
---|
77 |
// add a generic control for the streaming status |
---|
78 |
if(!m_genericContainer->addElement(new Control::StreamingStatus(*this))) { |
---|
79 |
debugWarning("failed to add StreamingStatus control to container\n"); |
---|
80 |
} |
---|
81 |
} |
---|
82 |
} |
---|
83 |
|
---|
84 |
FFADODevice::~FFADODevice() |
---|
85 |
{ |
---|
86 |
if (!deleteElement(&getConfigRom())) { |
---|
87 |
debugWarning("failed to remove ConfigRom from Control::Container\n"); |
---|
88 |
} |
---|
89 |
|
---|
90 |
// remove generic controls if present |
---|
91 |
if(m_genericContainer) { |
---|
92 |
if (!deleteElement(m_genericContainer)) { |
---|
93 |
debugError("Generic controls present but not registered to the avdevice\n"); |
---|
94 |
} |
---|
95 |
// remove and delete (as in free) child control elements |
---|
96 |
m_genericContainer->clearElements(true); |
---|
97 |
delete m_genericContainer; |
---|
98 |
} |
---|
99 |
} |
---|
100 |
|
---|
101 |
FFADODevice * |
---|
102 |
FFADODevice::createDevice(std::auto_ptr<ConfigRom>( x )) |
---|
103 |
{ |
---|
104 |
// re-implement this!! |
---|
105 |
assert(0); |
---|
106 |
return NULL; |
---|
107 |
} |
---|
108 |
|
---|
109 |
std::string |
---|
110 |
FFADODevice::getName() |
---|
111 |
{ |
---|
112 |
return getConfigRom().getGuidString(); |
---|
113 |
} |
---|
114 |
|
---|
115 |
int |
---|
116 |
FFADODevice::getNodeId() |
---|
117 |
{ |
---|
118 |
return getConfigRom().getNodeId(); |
---|
119 |
} |
---|
120 |
|
---|
121 |
bool FFADODevice::compareGUID( FFADODevice *a, FFADODevice *b ) { |
---|
122 |
assert(a); |
---|
123 |
assert(b); |
---|
124 |
return ConfigRom::compareGUID(a->getConfigRom(), b->getConfigRom()); |
---|
125 |
} |
---|
126 |
|
---|
127 |
ConfigRom& |
---|
128 |
FFADODevice::getConfigRom() const |
---|
129 |
{ |
---|
130 |
return *m_pConfigRom; |
---|
131 |
} |
---|
132 |
|
---|
133 |
Ieee1394Service& |
---|
134 |
FFADODevice::get1394Service() |
---|
135 |
{ |
---|
136 |
return getConfigRom().get1394Service(); |
---|
137 |
} |
---|
138 |
|
---|
139 |
bool |
---|
140 |
FFADODevice::loadFromCache() |
---|
141 |
{ |
---|
142 |
return false; |
---|
143 |
} |
---|
144 |
|
---|
145 |
bool |
---|
146 |
FFADODevice::saveCache() |
---|
147 |
{ |
---|
148 |
return false; |
---|
149 |
} |
---|
150 |
|
---|
151 |
bool |
---|
152 |
FFADODevice::needsRediscovery() |
---|
153 |
{ |
---|
154 |
// require rediscovery by default |
---|
155 |
return true; |
---|
156 |
} |
---|
157 |
|
---|
158 |
enum FFADODevice::eSyncState |
---|
159 |
FFADODevice::getSyncState( ) { |
---|
160 |
return eSS_Unknown; |
---|
161 |
} |
---|
162 |
|
---|
163 |
enum FFADODevice::eStreamingState |
---|
164 |
FFADODevice::getStreamingState() |
---|
165 |
{ |
---|
166 |
return eSS_Idle; |
---|
167 |
} |
---|
168 |
|
---|
169 |
bool |
---|
170 |
FFADODevice::setNickname( std::string name) |
---|
171 |
{ |
---|
172 |
return false; |
---|
173 |
} |
---|
174 |
|
---|
175 |
std::string |
---|
176 |
FFADODevice::getNickname() |
---|
177 |
{ |
---|
178 |
return "Unsupported"; |
---|
179 |
} |
---|
180 |
|
---|
181 |
bool |
---|
182 |
FFADODevice::canChangeNickname() |
---|
183 |
{ |
---|
184 |
return false; |
---|
185 |
} |
---|
186 |
|
---|
187 |
void |
---|
188 |
FFADODevice::handleBusReset() |
---|
189 |
{ |
---|
190 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Handle bus reset...\n"); |
---|
191 |
|
---|
192 |
// update the config rom node id |
---|
193 |
sleep(1); |
---|
194 |
|
---|
195 |
Util::MutexLockHelper lock(m_DeviceMutex); |
---|
196 |
getConfigRom().setVerboseLevel(getDebugLevel()); |
---|
197 |
getConfigRom().updatedNodeId(); |
---|
198 |
} |
---|
199 |
|
---|
200 |
void |
---|
201 |
FFADODevice::setVerboseLevel(int l) |
---|
202 |
{ |
---|
203 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); |
---|
204 |
setDebugLevel(l); |
---|
205 |
m_DeviceMutex.setVerboseLevel(l); |
---|
206 |
getConfigRom().setVerboseLevel(l); |
---|
207 |
} |
---|
208 |
|
---|
209 |
void |
---|
210 |
FFADODevice::showDevice() |
---|
211 |
{ |
---|
212 |
#ifdef DEBUG |
---|
213 |
Ieee1394Service& s = getConfigRom().get1394Service(); |
---|
214 |
debugOutput(DEBUG_LEVEL_NORMAL, "Attached to port.......: %d (%s)\n", |
---|
215 |
s.getPort(), s.getPortName().c_str()); |
---|
216 |
debugOutput(DEBUG_LEVEL_NORMAL, "Node...................: %d\n", getNodeId()); |
---|
217 |
debugOutput(DEBUG_LEVEL_NORMAL, "Vendor name............: %s\n", |
---|
218 |
getConfigRom().getVendorName().c_str()); |
---|
219 |
debugOutput(DEBUG_LEVEL_NORMAL, "Model name.............: %s\n", |
---|
220 |
getConfigRom().getModelName().c_str()); |
---|
221 |
debugOutput(DEBUG_LEVEL_NORMAL, "GUID...................: %s\n", |
---|
222 |
getConfigRom().getGuidString().c_str()); |
---|
223 |
|
---|
224 |
std::string id=std::string("dev? [none]"); |
---|
225 |
getOption("id", id); |
---|
226 |
|
---|
227 |
debugOutput(DEBUG_LEVEL_NORMAL, "Assigned ID....: %s\n", id.c_str()); |
---|
228 |
|
---|
229 |
flushDebugOutput(); |
---|
230 |
#endif |
---|
231 |
} |
---|
232 |
|
---|
233 |
|
---|
234 |
bool |
---|
235 |
FFADODevice::enableStreaming() { |
---|
236 |
return true; |
---|
237 |
} |
---|
238 |
|
---|
239 |
bool |
---|
240 |
FFADODevice::disableStreaming() { |
---|
241 |
return true; |
---|
242 |
} |
---|
243 |
|
---|
244 |
const char * |
---|
245 |
FFADODevice::ClockSourceTypeToString(enum eClockSourceType t) |
---|
246 |
{ |
---|
247 |
switch(t) { |
---|
248 |
default: return "Erratic type "; |
---|
249 |
case eCT_Invalid: return "Invalid "; |
---|
250 |
case eCT_Internal: return "Internal "; |
---|
251 |
case eCT_1394Bus: return "1394 Bus "; |
---|
252 |
case eCT_SytMatch: return "Compound Syt Match"; |
---|
253 |
case eCT_SytStream: return "Sync Syt Match "; |
---|
254 |
case eCT_WordClock: return "WordClock "; |
---|
255 |
case eCT_SPDIF: return "SPDIF "; |
---|
256 |
case eCT_ADAT: return "ADAT "; |
---|
257 |
case eCT_TDIF: return "TDIF "; |
---|
258 |
case eCT_AES: return "AES "; |
---|
259 |
} |
---|
260 |
} |
---|