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