1 |
/* bebob_avdevice.cpp |
---|
2 |
* Copyright (C) 2005,06 by Daniel Wagner |
---|
3 |
* |
---|
4 |
* This file is part of FreeBoB. |
---|
5 |
* |
---|
6 |
* FreeBoB is free software; you can redistribute it and/or modify |
---|
7 |
* it under the terms of the GNU General Public License as published by |
---|
8 |
* the Free Software Foundation; either version 2 of the License, or |
---|
9 |
* (at your option) any later version. |
---|
10 |
* FreeBoB is distributed in the hope that it will be useful, |
---|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 |
* GNU General Public License for more details. |
---|
14 |
* |
---|
15 |
* You should have received a copy of the GNU General Public License |
---|
16 |
* along with FreeBoB; if not, write to the Free Software |
---|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
18 |
* MA 02111-1307 USA. |
---|
19 |
*/ |
---|
20 |
|
---|
21 |
#include "bebob/bebob_avdevice.h" |
---|
22 |
#include "bebob/bebob_avdevice_subunit.h" |
---|
23 |
#include "configrom.h" |
---|
24 |
|
---|
25 |
#include "libfreebobavc/avc_plug_info.h" |
---|
26 |
#include "libfreebobavc/avc_extended_plug_info.h" |
---|
27 |
#include "libfreebobavc/avc_subunit_info.h" |
---|
28 |
#include "libfreebobavc/avc_extended_stream_format.h" |
---|
29 |
#include "libfreebobavc/serialize.h" |
---|
30 |
#include "libfreebobavc/ieee1394service.h" |
---|
31 |
#include "libfreebobavc/avc_definitions.h" |
---|
32 |
|
---|
33 |
#include "debugmodule/debugmodule.h" |
---|
34 |
|
---|
35 |
#include <iostream> |
---|
36 |
|
---|
37 |
namespace BeBoB { |
---|
38 |
|
---|
39 |
IMPL_DEBUG_MODULE( AvDevice, AvDevice, DEBUG_LEVEL_NORMAL ); |
---|
40 |
|
---|
41 |
AvDevice::AvDevice( std::auto_ptr< ConfigRom >( configRom ), |
---|
42 |
Ieee1394Service& ieee1394service, |
---|
43 |
int nodeId, |
---|
44 |
int verboseLevel ) |
---|
45 |
: m_configRom( configRom ) |
---|
46 |
, m_1394Service( &ieee1394service ) |
---|
47 |
, m_nodeId( nodeId ) |
---|
48 |
, m_verboseLevel( verboseLevel ) |
---|
49 |
, m_plugManager( verboseLevel ) |
---|
50 |
{ |
---|
51 |
if ( m_verboseLevel ) { |
---|
52 |
setDebugLevel( DEBUG_LEVEL_VERBOSE ); |
---|
53 |
} |
---|
54 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::AvDevice (NodeID %d)\n", |
---|
55 |
nodeId ); |
---|
56 |
} |
---|
57 |
|
---|
58 |
AvDevice::~AvDevice() |
---|
59 |
{ |
---|
60 |
for ( AvDeviceSubunitVector::iterator it = m_subunits.begin(); |
---|
61 |
it != m_subunits.end(); |
---|
62 |
++it ) |
---|
63 |
{ |
---|
64 |
delete *it; |
---|
65 |
} |
---|
66 |
for ( AvPlugConnectionVector::iterator it = m_plugConnections.begin(); |
---|
67 |
it != m_plugConnections.end(); |
---|
68 |
++it ) |
---|
69 |
{ |
---|
70 |
delete *it; |
---|
71 |
} |
---|
72 |
for ( AvPlugVector::iterator it = m_pcrPlugs.begin(); |
---|
73 |
it != m_pcrPlugs.end(); |
---|
74 |
++it ) |
---|
75 |
{ |
---|
76 |
delete *it; |
---|
77 |
} |
---|
78 |
for ( AvPlugVector::iterator it = m_externalPlugs.begin(); |
---|
79 |
it != m_externalPlugs.end(); |
---|
80 |
++it ) |
---|
81 |
{ |
---|
82 |
delete *it; |
---|
83 |
} |
---|
84 |
} |
---|
85 |
|
---|
86 |
ConfigRom& |
---|
87 |
AvDevice::getConfigRom() const |
---|
88 |
{ |
---|
89 |
return *m_configRom; |
---|
90 |
} |
---|
91 |
|
---|
92 |
struct VendorModelEntry { |
---|
93 |
unsigned int vendor_id; |
---|
94 |
unsigned int model_id; |
---|
95 |
}; |
---|
96 |
|
---|
97 |
static VendorModelEntry supportedDeviceList[] = |
---|
98 |
{ |
---|
99 |
{0x000d6c, 0x00010060}, // M-Audio, Audiophile |
---|
100 |
{0x0007f5, 0x00010048}, // BridgeCo, RD Audio1 |
---|
101 |
}; |
---|
102 |
|
---|
103 |
bool |
---|
104 |
AvDevice::probe( ConfigRom& configRom ) |
---|
105 |
{ |
---|
106 |
unsigned int vendorId = configRom.getNodeVendorId(); |
---|
107 |
unsigned int modelId = configRom.getModelId(); |
---|
108 |
|
---|
109 |
for ( unsigned int i = 0; |
---|
110 |
i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) ); |
---|
111 |
++i ) |
---|
112 |
{ |
---|
113 |
if ( ( supportedDeviceList[i].vendor_id == vendorId ) |
---|
114 |
&& ( supportedDeviceList[i].model_id == modelId ) ) |
---|
115 |
{ |
---|
116 |
return true; |
---|
117 |
} |
---|
118 |
} |
---|
119 |
|
---|
120 |
return false; |
---|
121 |
} |
---|
122 |
|
---|
123 |
bool |
---|
124 |
AvDevice::discover() |
---|
125 |
{ |
---|
126 |
if ( !enumerateSubUnits() ) { |
---|
127 |
debugError( "Could not enumarate sub units\n" ); |
---|
128 |
return false; |
---|
129 |
} |
---|
130 |
|
---|
131 |
if ( !discoverPlugs() ) { |
---|
132 |
debugError( "Detecting plugs failed\n" ); |
---|
133 |
return false; |
---|
134 |
} |
---|
135 |
|
---|
136 |
if ( !discoverPlugConnections() ) { |
---|
137 |
debugError( "Detecting plug connections failed\n" ); |
---|
138 |
return false; |
---|
139 |
} |
---|
140 |
|
---|
141 |
if ( !discoverSubUnitsPlugConnections() ) { |
---|
142 |
debugError( "Detecting plug connnection failed\n" ); |
---|
143 |
return false; |
---|
144 |
} |
---|
145 |
|
---|
146 |
if ( !discoverSyncModes() ) { |
---|
147 |
debugError( "Detecting sync modes failed\n" ); |
---|
148 |
return false; |
---|
149 |
} |
---|
150 |
|
---|
151 |
return true; |
---|
152 |
} |
---|
153 |
|
---|
154 |
bool |
---|
155 |
AvDevice::discoverPlugs() |
---|
156 |
{ |
---|
157 |
////////////////////////////////////////////// |
---|
158 |
// Get number of available isochronous input |
---|
159 |
// and output plugs of unit |
---|
160 |
|
---|
161 |
PlugInfoCmd plugInfoCmd( m_1394Service ); |
---|
162 |
plugInfoCmd.setNodeId( m_nodeId ); |
---|
163 |
plugInfoCmd.setCommandType( AVCCommand::eCT_Status ); |
---|
164 |
plugInfoCmd.setVerbose( m_verboseLevel ); |
---|
165 |
|
---|
166 |
if ( !plugInfoCmd.fire() ) { |
---|
167 |
debugError( "plug info command failed\n" ); |
---|
168 |
return false; |
---|
169 |
} |
---|
170 |
|
---|
171 |
debugOutput( DEBUG_LEVEL_NORMAL, "number of iso input plugs = %d\n", |
---|
172 |
plugInfoCmd.m_serialBusIsochronousInputPlugs ); |
---|
173 |
debugOutput( DEBUG_LEVEL_NORMAL, "number of iso output plugs = %d\n", |
---|
174 |
plugInfoCmd.m_serialBusIsochronousOutputPlugs ); |
---|
175 |
debugOutput( DEBUG_LEVEL_NORMAL, "number of external input plugs = %d\n", |
---|
176 |
plugInfoCmd.m_externalInputPlugs ); |
---|
177 |
debugOutput( DEBUG_LEVEL_NORMAL, "number of external output plugs = %d\n", |
---|
178 |
plugInfoCmd.m_externalOutputPlugs ); |
---|
179 |
|
---|
180 |
if ( !discoverPlugsPCR( AvPlug::eAPD_Input, |
---|
181 |
plugInfoCmd.m_serialBusIsochronousInputPlugs ) ) |
---|
182 |
{ |
---|
183 |
debugError( "pcr input plug discovering failed\n" ); |
---|
184 |
return false; |
---|
185 |
} |
---|
186 |
|
---|
187 |
if ( !discoverPlugsPCR( AvPlug::eAPD_Output, |
---|
188 |
plugInfoCmd.m_serialBusIsochronousOutputPlugs ) ) |
---|
189 |
{ |
---|
190 |
debugError( "pcr output plug discovering failed\n" ); |
---|
191 |
return false; |
---|
192 |
} |
---|
193 |
|
---|
194 |
if ( !discoverPlugsExternal( AvPlug::eAPD_Input, |
---|
195 |
plugInfoCmd.m_externalInputPlugs ) ) |
---|
196 |
{ |
---|
197 |
debugError( "external input plug discovering failed\n" ); |
---|
198 |
return false; |
---|
199 |
} |
---|
200 |
|
---|
201 |
if ( !discoverPlugsExternal( AvPlug::eAPD_Output, |
---|
202 |
plugInfoCmd.m_externalOutputPlugs ) ) |
---|
203 |
{ |
---|
204 |
debugError( "external output plug discovering failed\n" ); |
---|
205 |
return false; |
---|
206 |
} |
---|
207 |
|
---|
208 |
return true; |
---|
209 |
} |
---|
210 |
|
---|
211 |
bool |
---|
212 |
AvDevice::discoverPlugsPCR( AvPlug::EAvPlugDirection plugDirection, |
---|
213 |
plug_id_t plugMaxId ) |
---|
214 |
{ |
---|
215 |
for ( int plugId = 0; |
---|
216 |
plugId < plugMaxId; |
---|
217 |
++plugId ) |
---|
218 |
{ |
---|
219 |
AvPlug* plug = new AvPlug( *m_1394Service, |
---|
220 |
m_nodeId, |
---|
221 |
m_plugManager, |
---|
222 |
AVCCommand::eST_Unit, |
---|
223 |
0xff, |
---|
224 |
0xff, |
---|
225 |
0xff, |
---|
226 |
AvPlug::eAPA_PCR, |
---|
227 |
plugDirection, |
---|
228 |
plugId, |
---|
229 |
m_verboseLevel ); |
---|
230 |
if ( !plug || !plug->discover() ) { |
---|
231 |
debugError( "plug discovering failed\n" ); |
---|
232 |
delete plug; |
---|
233 |
return false; |
---|
234 |
} |
---|
235 |
|
---|
236 |
debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n", |
---|
237 |
plug->getName() ); |
---|
238 |
m_pcrPlugs.push_back( plug ); |
---|
239 |
} |
---|
240 |
|
---|
241 |
return true; |
---|
242 |
} |
---|
243 |
|
---|
244 |
bool |
---|
245 |
AvDevice::discoverPlugsExternal( AvPlug::EAvPlugDirection plugDirection, |
---|
246 |
plug_id_t plugMaxId ) |
---|
247 |
{ |
---|
248 |
for ( int plugId = 0; |
---|
249 |
plugId < plugMaxId; |
---|
250 |
++plugId ) |
---|
251 |
{ |
---|
252 |
AvPlug* plug = new AvPlug( *m_1394Service, |
---|
253 |
m_nodeId, |
---|
254 |
m_plugManager, |
---|
255 |
AVCCommand::eST_Unit, |
---|
256 |
0xff, |
---|
257 |
0xff, |
---|
258 |
0xff, |
---|
259 |
AvPlug::eAPA_ExternalPlug, |
---|
260 |
plugDirection, |
---|
261 |
plugId, |
---|
262 |
m_verboseLevel ); |
---|
263 |
if ( !plug || !plug->discover() ) { |
---|
264 |
debugError( "plug discovering failed\n" ); |
---|
265 |
return false; |
---|
266 |
} |
---|
267 |
|
---|
268 |
debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n", |
---|
269 |
plug->getName() ); |
---|
270 |
m_externalPlugs.push_back( plug ); |
---|
271 |
} |
---|
272 |
|
---|
273 |
return true; |
---|
274 |
} |
---|
275 |
|
---|
276 |
bool |
---|
277 |
AvDevice::discoverPlugConnections() |
---|
278 |
{ |
---|
279 |
for ( AvPlugVector::iterator it = m_pcrPlugs.begin(); |
---|
280 |
it != m_pcrPlugs.end(); |
---|
281 |
++it ) |
---|
282 |
{ |
---|
283 |
AvPlug* plug = *it; |
---|
284 |
if ( !plug->discoverConnections() ) { |
---|
285 |
debugError( "Could not discover plug connections\n" ); |
---|
286 |
return false; |
---|
287 |
} |
---|
288 |
} |
---|
289 |
for ( AvPlugVector::iterator it = m_externalPlugs.begin(); |
---|
290 |
it != m_externalPlugs.end(); |
---|
291 |
++it ) |
---|
292 |
{ |
---|
293 |
AvPlug* plug = *it; |
---|
294 |
if ( !plug->discoverConnections() ) { |
---|
295 |
debugError( "Could not discover plug connections\n" ); |
---|
296 |
return false; |
---|
297 |
} |
---|
298 |
} |
---|
299 |
|
---|
300 |
return true; |
---|
301 |
} |
---|
302 |
|
---|
303 |
bool |
---|
304 |
AvDevice::discoverSubUnitsPlugConnections() |
---|
305 |
{ |
---|
306 |
for ( AvDeviceSubunitVector::iterator it = m_subunits.begin(); |
---|
307 |
it != m_subunits.end(); |
---|
308 |
++it ) |
---|
309 |
{ |
---|
310 |
AvDeviceSubunit* subunit = *it; |
---|
311 |
if ( !subunit->discoverConnections() ) { |
---|
312 |
debugError( "Subunit '%s' plug connections failed\n", |
---|
313 |
subunit->getName() ); |
---|
314 |
return false; |
---|
315 |
} |
---|
316 |
} |
---|
317 |
return true; |
---|
318 |
} |
---|
319 |
|
---|
320 |
bool |
---|
321 |
AvDevice::discoverSyncModes() |
---|
322 |
{ |
---|
323 |
// Following possible sync plugs exists: |
---|
324 |
// - Music subunit sync output plug = internal sync (CSP) |
---|
325 |
// - Unit input plug 0 = SYT match |
---|
326 |
// - Unit input plut 1 = Sync stream |
---|
327 |
// |
---|
328 |
// If last sync mode is reported it is mostelikely not |
---|
329 |
// implemented *sic* |
---|
330 |
// |
---|
331 |
// Following sync sources are device specific: |
---|
332 |
// - All unit external input plugs which have a |
---|
333 |
// sync information (WS, SPDIF, ...) |
---|
334 |
|
---|
335 |
// First we have to find the sync input and output plug |
---|
336 |
// in the music subunit. |
---|
337 |
|
---|
338 |
// Note PCR input means 1394bus-to-device where as |
---|
339 |
// MSU input means subunit-to-device |
---|
340 |
|
---|
341 |
AvPlugVector syncPCRInputPlugs = getPlugsByType( m_pcrPlugs, |
---|
342 |
AvPlug::eAPD_Input, |
---|
343 |
AvPlug::eAPT_Sync ); |
---|
344 |
if ( !syncPCRInputPlugs.size() ) { |
---|
345 |
debugWarning( "No PCR sync input plug found\n" ); |
---|
346 |
} |
---|
347 |
|
---|
348 |
AvPlugVector syncPCROutputPlugs = getPlugsByType( m_pcrPlugs, |
---|
349 |
AvPlug::eAPD_Output, |
---|
350 |
AvPlug::eAPT_Sync ); |
---|
351 |
if ( !syncPCROutputPlugs.size() ) { |
---|
352 |
debugWarning( "No PCR sync output plug found\n" ); |
---|
353 |
} |
---|
354 |
|
---|
355 |
AvPlugVector isoPCRInputPlugs = getPlugsByType( m_pcrPlugs, |
---|
356 |
AvPlug::eAPD_Input, |
---|
357 |
AvPlug::eAPT_IsoStream ); |
---|
358 |
if ( !isoPCRInputPlugs.size() ) { |
---|
359 |
debugWarning( "No PCR iso input plug found\n" ); |
---|
360 |
|
---|
361 |
} |
---|
362 |
|
---|
363 |
AvPlugVector isoPCROutputPlugs = getPlugsByType( m_pcrPlugs, |
---|
364 |
AvPlug::eAPD_Output, |
---|
365 |
AvPlug::eAPT_IsoStream ); |
---|
366 |
if ( !isoPCROutputPlugs.size() ) { |
---|
367 |
debugWarning( "No PCR iso output plug found\n" ); |
---|
368 |
|
---|
369 |
} |
---|
370 |
|
---|
371 |
AvPlugVector digitalPCRInputPlugs = getPlugsByType( m_externalPlugs, |
---|
372 |
AvPlug::eAPD_Input, |
---|
373 |
AvPlug::eAPT_Digital ); |
---|
374 |
|
---|
375 |
AvPlugVector syncMSUInputPlugs = m_plugManager.getPlugsByType( |
---|
376 |
AVCCommand::eST_Music, |
---|
377 |
0, |
---|
378 |
0xff, |
---|
379 |
0xff, |
---|
380 |
AvPlug::eAPA_SubunitPlug, |
---|
381 |
AvPlug::eAPD_Input, |
---|
382 |
AvPlug::eAPT_Sync ); |
---|
383 |
if ( !syncMSUInputPlugs.size() ) { |
---|
384 |
debugWarning( "No sync input plug for MSU subunit found\n" ); |
---|
385 |
} |
---|
386 |
|
---|
387 |
AvPlugVector syncMSUOutputPlugs = m_plugManager.getPlugsByType( |
---|
388 |
AVCCommand::eST_Music, |
---|
389 |
0, |
---|
390 |
0xff, |
---|
391 |
0xff, |
---|
392 |
AvPlug::eAPA_SubunitPlug, |
---|
393 |
AvPlug::eAPD_Output, |
---|
394 |
AvPlug::eAPT_Sync ); |
---|
395 |
if ( !syncMSUOutputPlugs.size() ) { |
---|
396 |
debugWarning( "No sync output plug for MSU subunit found\n" ); |
---|
397 |
} |
---|
398 |
|
---|
399 |
debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Input Plugs:\n" ); |
---|
400 |
showAvPlugs( syncPCRInputPlugs ); |
---|
401 |
debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Output Plugs:\n" ); |
---|
402 |
showAvPlugs( syncPCROutputPlugs ); |
---|
403 |
debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Input Plugs:\n" ); |
---|
404 |
showAvPlugs( isoPCRInputPlugs ); |
---|
405 |
debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Output Plugs:\n" ); |
---|
406 |
showAvPlugs( isoPCROutputPlugs ); |
---|
407 |
debugOutput( DEBUG_LEVEL_VERBOSE, "PCR digital Input Plugs:\n" ); |
---|
408 |
showAvPlugs( digitalPCRInputPlugs ); |
---|
409 |
debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Input Plugs:\n" ); |
---|
410 |
showAvPlugs( syncMSUInputPlugs ); |
---|
411 |
debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Output Plugs:\n" ); |
---|
412 |
showAvPlugs( syncMSUOutputPlugs ); |
---|
413 |
|
---|
414 |
// Check all possible PCR input to MSU input connections |
---|
415 |
// -> sync stream input |
---|
416 |
checkSyncConnections( syncPCRInputPlugs, syncMSUInputPlugs ); |
---|
417 |
|
---|
418 |
// Check all possible MSU output to PCR output connections |
---|
419 |
// -> sync stream output |
---|
420 |
checkSyncConnections( syncMSUOutputPlugs, syncPCROutputPlugs ); |
---|
421 |
|
---|
422 |
// Check all PCR iso input to MSU input connections |
---|
423 |
// -> SYT match |
---|
424 |
checkSyncConnections( isoPCRInputPlugs, syncMSUInputPlugs ); |
---|
425 |
|
---|
426 |
// Check all MSU sync output to MSU input connections |
---|
427 |
// -> CSP |
---|
428 |
checkSyncConnections( syncMSUOutputPlugs, syncMSUInputPlugs ); |
---|
429 |
|
---|
430 |
// Check all external PCR digital input to MSU input connections |
---|
431 |
// -> SPDIF/ADAT sync |
---|
432 |
checkSyncConnections( digitalPCRInputPlugs, syncMSUInputPlugs ); |
---|
433 |
|
---|
434 |
|
---|
435 |
// Currently active connection signal sourqce cmd, command type |
---|
436 |
// status, source unknown, destination MSU sync input plug |
---|
437 |
|
---|
438 |
for ( AvPlugVector::const_iterator it = syncMSUInputPlugs.begin(); |
---|
439 |
it != syncMSUInputPlugs.end(); |
---|
440 |
++it ) |
---|
441 |
{ |
---|
442 |
AvPlug* msuPlug = *it; |
---|
443 |
for ( AvPlugVector::const_iterator jt = |
---|
444 |
msuPlug->getInputConnections().begin(); |
---|
445 |
jt != msuPlug->getInputConnections().end(); |
---|
446 |
++jt ) |
---|
447 |
{ |
---|
448 |
AvPlug* plug = *jt; |
---|
449 |
plug = plug; // disable compiler warning in release mode |
---|
450 |
// will be optimized away |
---|
451 |
debugOutput( DEBUG_LEVEL_NORMAL, |
---|
452 |
"Active Sync Connection: '%s' -> '%s'\n", |
---|
453 |
msuPlug->getName(), |
---|
454 |
plug->getName() ); |
---|
455 |
} |
---|
456 |
} |
---|
457 |
|
---|
458 |
return true; |
---|
459 |
} |
---|
460 |
|
---|
461 |
bool |
---|
462 |
AvDevice::enumerateSubUnits() |
---|
463 |
{ |
---|
464 |
SubUnitInfoCmd subUnitInfoCmd( m_1394Service ); |
---|
465 |
//subUnitInfoCmd.setVerbose( 1 ); |
---|
466 |
subUnitInfoCmd.setCommandType( AVCCommand::eCT_Status ); |
---|
467 |
|
---|
468 |
// BeBoB has always exactly one audio and one music subunit. This |
---|
469 |
// means is fits into the first page of the SubUnitInfo command. |
---|
470 |
// So there is no need to do more than needed |
---|
471 |
|
---|
472 |
subUnitInfoCmd.m_page = 0; |
---|
473 |
subUnitInfoCmd.setNodeId( m_nodeId ); |
---|
474 |
subUnitInfoCmd.setVerbose( m_verboseLevel ); |
---|
475 |
if ( !subUnitInfoCmd.fire() ) { |
---|
476 |
debugError( "Subunit info command failed\n" ); |
---|
477 |
} |
---|
478 |
|
---|
479 |
for ( int i = 0; i < subUnitInfoCmd.getNrOfValidEntries(); ++i ) { |
---|
480 |
subunit_type_t subunit_type |
---|
481 |
= subUnitInfoCmd.m_table[i].m_subunit_type; |
---|
482 |
|
---|
483 |
unsigned int subunitId = getNrOfSubunits( subunit_type ); |
---|
484 |
|
---|
485 |
debugOutput( DEBUG_LEVEL_VERBOSE, |
---|
486 |
"subunit_id = %2d, subunit_type = %2d (%s)\n", |
---|
487 |
subunitId, |
---|
488 |
subunit_type, |
---|
489 |
subunitTypeToString( subunit_type ) ); |
---|
490 |
|
---|
491 |
AvDeviceSubunit* subunit = 0; |
---|
492 |
switch( subunit_type ) { |
---|
493 |
case AVCCommand::eST_Audio: |
---|
494 |
subunit = new AvDeviceSubunitAudio( *this, subunitId, |
---|
495 |
m_verboseLevel ); |
---|
496 |
if ( !subunit ) { |
---|
497 |
debugFatal( "Could not allocate AvDeviceSubunitAudio\n" ); |
---|
498 |
return false; |
---|
499 |
} |
---|
500 |
break; |
---|
501 |
case AVCCommand::eST_Music: |
---|
502 |
subunit = new AvDeviceSubunitMusic( *this, subunitId, |
---|
503 |
m_verboseLevel ); |
---|
504 |
if ( !subunit ) { |
---|
505 |
debugFatal( "Could not allocate AvDeviceSubunitMusic\n" ); |
---|
506 |
return false; |
---|
507 |
} |
---|
508 |
break; |
---|
509 |
default: |
---|
510 |
debugOutput( DEBUG_LEVEL_NORMAL, |
---|
511 |
"Unsupported subunit found, subunit_type = %d (%s)\n", |
---|
512 |
subunit_type, |
---|
513 |
subunitTypeToString( subunit_type ) ); |
---|
514 |
continue; |
---|
515 |
|
---|
516 |
} |
---|
517 |
|
---|
518 |
if ( !subunit->discover() ) { |
---|
519 |
debugError( "enumerateSubUnits: Could not discover " |
---|
520 |
"subunit_id = %2d, subunit_type = %2d (%s)\n", |
---|
521 |
subunitId, |
---|
522 |
subunit_type, |
---|
523 |
subunitTypeToString( subunit_type ) ); |
---|
524 |
delete subunit; |
---|
525 |
return false; |
---|
526 |
} |
---|
527 |
m_subunits.push_back( subunit ); |
---|
528 |
} |
---|
529 |
|
---|
530 |
return true; |
---|
531 |
} |
---|
532 |
|
---|
533 |
|
---|
534 |
AvDeviceSubunit* |
---|
535 |
AvDevice::getSubunit( subunit_type_t subunitType, |
---|
536 |
subunit_id_t subunitId ) const |
---|
537 |
{ |
---|
538 |
for ( AvDeviceSubunitVector::const_iterator it = m_subunits.begin(); |
---|
539 |
it != m_subunits.end(); |
---|
540 |
++it ) |
---|
541 |
{ |
---|
542 |
AvDeviceSubunit* subunit = *it; |
---|
543 |
if ( ( subunitType == subunit->getSubunitType() ) |
---|
544 |
&& ( subunitId == subunit->getSubunitId() ) ) |
---|
545 |
{ |
---|
546 |
return subunit; |
---|
547 |
} |
---|
548 |
} |
---|
549 |
|
---|
550 |
return 0; |
---|
551 |
} |
---|
552 |
|
---|
553 |
|
---|
554 |
unsigned int |
---|
555 |
AvDevice::getNrOfSubunits( subunit_type_t subunitType ) const |
---|
556 |
{ |
---|
557 |
unsigned int nrOfSubunits = 0; |
---|
558 |
|
---|
559 |
for ( AvDeviceSubunitVector::const_iterator it = m_subunits.begin(); |
---|
560 |
it != m_subunits.end(); |
---|
561 |
++it ) |
---|
562 |
{ |
---|
563 |
AvDeviceSubunit* subunit = *it; |
---|
564 |
if ( subunitType == subunit->getSubunitType() ) { |
---|
565 |
nrOfSubunits++; |
---|
566 |
} |
---|
567 |
} |
---|
568 |
|
---|
569 |
return nrOfSubunits; |
---|
570 |
} |
---|
571 |
|
---|
572 |
AvPlugConnection* |
---|
573 |
AvDevice::getPlugConnection( AvPlug& srcPlug ) const |
---|
574 |
{ |
---|
575 |
for ( AvPlugConnectionVector::const_iterator it |
---|
576 |
= m_plugConnections.begin(); |
---|
577 |
it != m_plugConnections.end(); |
---|
578 |
++it ) |
---|
579 |
{ |
---|
580 |
AvPlugConnection* plugConnection = *it; |
---|
581 |
if ( &( plugConnection->getSrcPlug() ) == &srcPlug ) { |
---|
582 |
return plugConnection; |
---|
583 |
} |
---|
584 |
} |
---|
585 |
|
---|
586 |
return 0; |
---|
587 |
} |
---|
588 |
|
---|
589 |
AvPlug* |
---|
590 |
AvDevice::getPlugById( AvPlugVector& plugs, |
---|
591 |
AvPlug::EAvPlugDirection plugDirection, |
---|
592 |
int id ) |
---|
593 |
{ |
---|
594 |
for ( AvPlugVector::iterator it = plugs.begin(); |
---|
595 |
it != plugs.end(); |
---|
596 |
++it ) |
---|
597 |
{ |
---|
598 |
AvPlug* plug = *it; |
---|
599 |
if ( ( id == plug->getPlugId() ) |
---|
600 |
&& ( plugDirection == plug->getPlugDirection() ) ) |
---|
601 |
{ |
---|
602 |
return plug; |
---|
603 |
} |
---|
604 |
} |
---|
605 |
|
---|
606 |
return 0; |
---|
607 |
} |
---|
608 |
|
---|
609 |
AvPlugVector |
---|
610 |
AvDevice::getPlugsByType( AvPlugVector& plugs, |
---|
611 |
AvPlug::EAvPlugDirection plugDirection, |
---|
612 |
AvPlug::EAvPlugType type) |
---|
613 |
{ |
---|
614 |
AvPlugVector plugVector; |
---|
615 |
for ( AvPlugVector::iterator it = plugs.begin(); |
---|
616 |
it != plugs.end(); |
---|
617 |
++it ) |
---|
618 |
{ |
---|
619 |
AvPlug* plug = *it; |
---|
620 |
if ( ( type == plug->getPlugType() ) |
---|
621 |
&& ( plugDirection == plug->getPlugDirection() ) ) |
---|
622 |
{ |
---|
623 |
plugVector.push_back( plug ); |
---|
624 |
} |
---|
625 |
} |
---|
626 |
|
---|
627 |
return plugVector; |
---|
628 |
} |
---|
629 |
|
---|
630 |
AvPlug* |
---|
631 |
AvDevice::getSyncPlug( int maxPlugId, AvPlug::EAvPlugDirection ) |
---|
632 |
{ |
---|
633 |
return 0; |
---|
634 |
} |
---|
635 |
|
---|
636 |
bool |
---|
637 |
AvDevice::setSamplingFrequency( ESamplingFrequency samplingFrequency ) |
---|
638 |
{ |
---|
639 |
|
---|
640 |
AvPlug* plug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Input, 0 ); |
---|
641 |
if ( !plug ) { |
---|
642 |
debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); |
---|
643 |
return false; |
---|
644 |
} |
---|
645 |
|
---|
646 |
if ( !setSamplingFrequencyPlug( *plug, |
---|
647 |
AvPlug::eAPD_Input, |
---|
648 |
samplingFrequency ) ) |
---|
649 |
{ |
---|
650 |
debugError( "setSampleRate: Setting sample rate failed\n" ); |
---|
651 |
return false; |
---|
652 |
} |
---|
653 |
|
---|
654 |
plug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Output, 0 ); |
---|
655 |
if ( !plug ) { |
---|
656 |
debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); |
---|
657 |
return false; |
---|
658 |
} |
---|
659 |
|
---|
660 |
if ( !setSamplingFrequencyPlug( *plug, |
---|
661 |
AvPlug::eAPD_Output, |
---|
662 |
samplingFrequency ) ) |
---|
663 |
{ |
---|
664 |
debugError( "setSampleRate: Setting sample rate failed\n" ); |
---|
665 |
return false; |
---|
666 |
} |
---|
667 |
|
---|
668 |
|
---|
669 |
debugOutput( DEBUG_LEVEL_VERBOSE, |
---|
670 |
"setSampleRate: Set sample rate to %d\n", |
---|
671 |
convertESamplingFrequency( samplingFrequency ) ); |
---|
672 |
return true; |
---|
673 |
} |
---|
674 |
|
---|
675 |
bool |
---|
676 |
AvDevice::setSamplingFrequencyPlug( AvPlug& plug, |
---|
677 |
AvPlug::EAvPlugDirection direction, |
---|
678 |
ESamplingFrequency samplingFrequency ) |
---|
679 |
{ |
---|
680 |
|
---|
681 |
ExtendedStreamFormatCmd extStreamFormatCmd( |
---|
682 |
m_1394Service, |
---|
683 |
ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommandList ); |
---|
684 |
UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, |
---|
685 |
plug.getPlugId() ); |
---|
686 |
|
---|
687 |
extStreamFormatCmd.setPlugAddress( |
---|
688 |
PlugAddress( |
---|
689 |
AvPlug::convertPlugDirection(direction ), |
---|
690 |
PlugAddress::ePAM_Unit, |
---|
691 |
unitPlugAddress ) ); |
---|
692 |
|
---|
693 |
extStreamFormatCmd.setNodeId( m_nodeId ); |
---|
694 |
extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status ); |
---|
695 |
|
---|
696 |
int i = 0; |
---|
697 |
bool cmdSuccess = false; |
---|
698 |
bool correctFormatFound = false; |
---|
699 |
|
---|
700 |
do { |
---|
701 |
extStreamFormatCmd.setIndexInStreamFormat( i ); |
---|
702 |
extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status ); |
---|
703 |
extStreamFormatCmd.setVerbose( m_verboseLevel ); |
---|
704 |
|
---|
705 |
cmdSuccess = extStreamFormatCmd.fire(); |
---|
706 |
|
---|
707 |
if ( cmdSuccess |
---|
708 |
&& ( extStreamFormatCmd.getResponse() == |
---|
709 |
AVCCommand::eR_Implemented ) ) |
---|
710 |
{ |
---|
711 |
ESamplingFrequency foundFreq = eSF_DontCare; |
---|
712 |
|
---|
713 |
FormatInformation* formatInfo = |
---|
714 |
extStreamFormatCmd.getFormatInformation(); |
---|
715 |
FormatInformationStreamsCompound* compoundStream |
---|
716 |
= dynamic_cast< FormatInformationStreamsCompound* > ( |
---|
717 |
formatInfo->m_streams ); |
---|
718 |
if ( compoundStream ) { |
---|
719 |
foundFreq = |
---|
720 |
static_cast<ESamplingFrequency>( |
---|
721 |
compoundStream->m_samplingFrequency ); |
---|
722 |
} |
---|
723 |
|
---|
724 |
FormatInformationStreamsSync* syncStream |
---|
725 |
= dynamic_cast< FormatInformationStreamsSync* > ( |
---|
726 |
formatInfo->m_streams ); |
---|
727 |
if ( syncStream ) { |
---|
728 |
foundFreq = |
---|
729 |
static_cast<ESamplingFrequency>( |
---|
730 |
compoundStream->m_samplingFrequency ); |
---|
731 |
} |
---|
732 |
|
---|
733 |
if ( foundFreq == samplingFrequency ) |
---|
734 |
{ |
---|
735 |
correctFormatFound = true; |
---|
736 |
break; |
---|
737 |
} |
---|
738 |
} |
---|
739 |
|
---|
740 |
++i; |
---|
741 |
} while ( cmdSuccess |
---|
742 |
&& ( extStreamFormatCmd.getResponse() == |
---|
743 |
ExtendedStreamFormatCmd::eR_Implemented ) |
---|
744 |
&& ( extStreamFormatCmd.getStatus() != |
---|
745 |
ExtendedStreamFormatCmd::eS_NotUsed ) ); |
---|
746 |
|
---|
747 |
if ( !cmdSuccess ) { |
---|
748 |
debugError( "setSampleRatePlug: Failed to retrieve format info\n" ); |
---|
749 |
return false; |
---|
750 |
} |
---|
751 |
|
---|
752 |
if ( !correctFormatFound ) { |
---|
753 |
debugError( "setSampleRatePlug: %s plug %d does not support " |
---|
754 |
"sample rate %d\n", |
---|
755 |
plug.getName(), |
---|
756 |
plug.getPlugId(), |
---|
757 |
convertESamplingFrequency( samplingFrequency ) ); |
---|
758 |
return false; |
---|
759 |
} |
---|
760 |
|
---|
761 |
extStreamFormatCmd.setSubFunction( |
---|
762 |
ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommand ); |
---|
763 |
extStreamFormatCmd.setCommandType( AVCCommand::eCT_Control ); |
---|
764 |
extStreamFormatCmd.setVerbose( m_verboseLevel ); |
---|
765 |
|
---|
766 |
if ( !extStreamFormatCmd.fire() ) { |
---|
767 |
debugError( "setSampleRate: Could not set sample rate %d " |
---|
768 |
"to %s plug %d\n", |
---|
769 |
convertESamplingFrequency( samplingFrequency ), |
---|
770 |
plug.getName(), |
---|
771 |
plug.getPlugId() ); |
---|
772 |
return false; |
---|
773 |
} |
---|
774 |
|
---|
775 |
return true; |
---|
776 |
} |
---|
777 |
|
---|
778 |
void |
---|
779 |
AvDevice::showDevice() const |
---|
780 |
{ |
---|
781 |
m_plugManager.showPlugs(); |
---|
782 |
} |
---|
783 |
|
---|
784 |
void |
---|
785 |
AvDevice::showAvPlugs( AvPlugVector& plugs ) const |
---|
786 |
{ |
---|
787 |
int i = 0; |
---|
788 |
for ( AvPlugVector::const_iterator it = plugs.begin(); |
---|
789 |
it != plugs.end(); |
---|
790 |
++it, ++i ) |
---|
791 |
{ |
---|
792 |
AvPlug* plug = *it; |
---|
793 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Plug %d\n", i ); |
---|
794 |
plug->showPlug(); |
---|
795 |
} |
---|
796 |
} |
---|
797 |
|
---|
798 |
bool |
---|
799 |
AvDevice::checkSyncConnections( AvPlugVector& plhs, AvPlugVector& prhs ) |
---|
800 |
{ |
---|
801 |
for ( AvPlugVector::iterator plIt = plhs.begin(); |
---|
802 |
plIt != plhs.end(); |
---|
803 |
++plIt ) |
---|
804 |
{ |
---|
805 |
AvPlug* pl = *plIt; |
---|
806 |
for ( AvPlugVector::iterator prIt = prhs.begin(); |
---|
807 |
prIt != prhs.end(); |
---|
808 |
++prIt ) |
---|
809 |
{ |
---|
810 |
AvPlug* pr = *prIt; |
---|
811 |
if ( pl->inquireConnnection( *pr ) ) { |
---|
812 |
debugOutput( DEBUG_LEVEL_NORMAL, |
---|
813 |
"Sync connection '%s' -> '%s'\n", |
---|
814 |
pl->getName(), |
---|
815 |
pr->getName() ); |
---|
816 |
} |
---|
817 |
} |
---|
818 |
} |
---|
819 |
return true; |
---|
820 |
} |
---|
821 |
|
---|
822 |
bool AvDevice::setId( unsigned int id) { |
---|
823 |
return true; |
---|
824 |
} |
---|
825 |
|
---|
826 |
} |
---|