1 |
/* maudio_avdevice.cpp |
---|
2 |
* Copyright (C) 2006 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 |
#include "maudio/maudio_avdevice.h" |
---|
21 |
#include "bebob/bebob_avdevice.h" |
---|
22 |
|
---|
23 |
#include "libieee1394/configrom.h" |
---|
24 |
#include "libieee1394/ieee1394service.h" |
---|
25 |
|
---|
26 |
#include "libfreebobavc/avc_definitions.h" |
---|
27 |
|
---|
28 |
#include "debugmodule/debugmodule.h" |
---|
29 |
|
---|
30 |
#include <libxml/xmlmemory.h> |
---|
31 |
#include <libxml/parser.h> |
---|
32 |
|
---|
33 |
#include <string> |
---|
34 |
#include <stdint.h> |
---|
35 |
|
---|
36 |
namespace MAudio { |
---|
37 |
|
---|
38 |
IMPL_DEBUG_MODULE( AvDevice, AvDevice, DEBUG_LEVEL_NORMAL ); |
---|
39 |
|
---|
40 |
AvDevice::AvDevice( std::auto_ptr< ConfigRom >( configRom ), |
---|
41 |
Ieee1394Service& ieee1394service, |
---|
42 |
int iNodeId, |
---|
43 |
int iVerboseLevel ) |
---|
44 |
: BeBoB::AvDevice( configRom, |
---|
45 |
ieee1394service, |
---|
46 |
iNodeId, |
---|
47 |
iVerboseLevel ) |
---|
48 |
, m_model ( NULL ) |
---|
49 |
{ |
---|
50 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Created MAudio::AvDevice (NodeID %d)\n", |
---|
51 |
iNodeId ); |
---|
52 |
} |
---|
53 |
|
---|
54 |
AvDevice::~AvDevice() |
---|
55 |
{ |
---|
56 |
} |
---|
57 |
|
---|
58 |
static VendorModelEntry supportedDeviceList[] = |
---|
59 |
{ |
---|
60 |
//{0x0007f5, 0x00010048, "BridgeCo", "RD Audio1", "refdesign.xml"}, |
---|
61 |
|
---|
62 |
{0x000d6c, 0x00010046, "M-Audio", "FW 410", "fw410.xml"}, |
---|
63 |
{0x000d6c, 0x00010058, "M-Audio", "FW 410", "fw410.xml"}, // Version 5.10.0.5036 |
---|
64 |
{0x000d6c, 0x00010060, "M-Audio", "FW Audiophile", "fwap.xml"}, |
---|
65 |
}; |
---|
66 |
|
---|
67 |
bool |
---|
68 |
AvDevice::probe( ConfigRom& configRom ) |
---|
69 |
{ |
---|
70 |
unsigned int iVendorId = configRom.getNodeVendorId(); |
---|
71 |
unsigned int iModelId = configRom.getModelId(); |
---|
72 |
|
---|
73 |
for ( unsigned int i = 0; |
---|
74 |
i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) ); |
---|
75 |
++i ) |
---|
76 |
{ |
---|
77 |
if ( ( supportedDeviceList[i].vendor_id == iVendorId ) |
---|
78 |
&& ( supportedDeviceList[i].model_id == iModelId ) ) |
---|
79 |
{ |
---|
80 |
return true; |
---|
81 |
} |
---|
82 |
} |
---|
83 |
return false; |
---|
84 |
} |
---|
85 |
|
---|
86 |
bool |
---|
87 |
AvDevice::discover() |
---|
88 |
{ |
---|
89 |
unsigned int vendorId = m_pConfigRom->getNodeVendorId(); |
---|
90 |
unsigned int modelId = m_pConfigRom->getModelId(); |
---|
91 |
|
---|
92 |
for ( unsigned int i = 0; |
---|
93 |
i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) ); |
---|
94 |
++i ) |
---|
95 |
{ |
---|
96 |
if ( ( supportedDeviceList[i].vendor_id == vendorId ) |
---|
97 |
&& ( supportedDeviceList[i].model_id == modelId ) |
---|
98 |
) |
---|
99 |
{ |
---|
100 |
m_model = &(supportedDeviceList[i]); |
---|
101 |
break; |
---|
102 |
} |
---|
103 |
} |
---|
104 |
|
---|
105 |
if (m_model != NULL) { |
---|
106 |
debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n", |
---|
107 |
m_model->vendor_name, m_model->model_name); |
---|
108 |
} else return false; |
---|
109 |
|
---|
110 |
return true; |
---|
111 |
} |
---|
112 |
|
---|
113 |
bool |
---|
114 |
AvDevice::setSamplingFrequency( ESamplingFrequency eSamplingFrequency ) |
---|
115 |
{ |
---|
116 |
// not supported |
---|
117 |
return false; |
---|
118 |
} |
---|
119 |
|
---|
120 |
int AvDevice::getSamplingFrequency( ) { |
---|
121 |
return 44100; |
---|
122 |
} |
---|
123 |
|
---|
124 |
void |
---|
125 |
AvDevice::showDevice() const |
---|
126 |
{ |
---|
127 |
} |
---|
128 |
|
---|
129 |
bool |
---|
130 |
AvDevice::addXmlDescription( xmlNodePtr pDeviceNode ) |
---|
131 |
{ |
---|
132 |
char* pFilename; |
---|
133 |
if ( asprintf( &pFilename, "%s/libfreebob/maudio/%s", DATADIR, m_model->filename ) < 0 ) { |
---|
134 |
debugError( "addXmlDescription: Could not create filename string\n" ); |
---|
135 |
return false; |
---|
136 |
} |
---|
137 |
|
---|
138 |
xmlDocPtr pDoc = xmlParseFile( pFilename ); |
---|
139 |
|
---|
140 |
if ( !pDoc ) { |
---|
141 |
debugError( "addXmlDescription: No file '%s' found'\n", pFilename ); |
---|
142 |
free( pFilename ); |
---|
143 |
return false;; |
---|
144 |
} |
---|
145 |
|
---|
146 |
xmlNodePtr pCur = xmlDocGetRootElement( pDoc ); |
---|
147 |
if ( !pCur ) { |
---|
148 |
debugError( "addXmlDescription: Document '%s' has not root element\n", pFilename ); |
---|
149 |
xmlFreeDoc( pDoc ); |
---|
150 |
free( pFilename ); |
---|
151 |
return false; |
---|
152 |
} |
---|
153 |
|
---|
154 |
if ( xmlStrcmp( pCur->name, ( const xmlChar * ) "FreeBoBConnectionInfo" ) ) { |
---|
155 |
debugError( "addXmlDescription: No node 'FreeBoBConnectionInfo' found\n" ); |
---|
156 |
xmlFreeDoc( pDoc ); |
---|
157 |
free( pFilename ); |
---|
158 |
return false; |
---|
159 |
} |
---|
160 |
|
---|
161 |
pCur = pCur->xmlChildrenNode; |
---|
162 |
while ( pCur ) { |
---|
163 |
if ( !xmlStrcmp( pCur->name, ( const xmlChar * ) "Device" ) ) { |
---|
164 |
break; |
---|
165 |
} |
---|
166 |
pCur = pCur->next; |
---|
167 |
} |
---|
168 |
|
---|
169 |
if ( pCur ) { |
---|
170 |
pCur = pCur->xmlChildrenNode; |
---|
171 |
while ( pCur ) { |
---|
172 |
if ( ( !xmlStrcmp( pCur->name, ( const xmlChar * ) "ConnectionSet" ) ) ) { |
---|
173 |
xmlNodePtr pDevDesc = xmlCopyNode( pCur, 1 ); |
---|
174 |
if ( !pDevDesc ) { |
---|
175 |
debugError( "addXmlDescription: Could not copy node 'ConnectionSet'\n" ); |
---|
176 |
xmlFreeDoc( pDoc ); |
---|
177 |
free( pFilename ); |
---|
178 |
return false; |
---|
179 |
} |
---|
180 |
|
---|
181 |
// set correct node id |
---|
182 |
for ( xmlNodePtr pNode = pDevDesc->xmlChildrenNode; pNode; pNode = pNode->next ) { |
---|
183 |
if ( ( !xmlStrcmp( pNode->name, ( const xmlChar * ) "Connection" ) ) ) { |
---|
184 |
for ( xmlNodePtr pSubNode = pNode->xmlChildrenNode; pSubNode; pSubNode = pSubNode->next ) { |
---|
185 |
if ( ( !xmlStrcmp( pSubNode->name, ( const xmlChar * ) "Node" ) ) ) { |
---|
186 |
char* result; |
---|
187 |
asprintf( &result, "%d", m_nodeId ); |
---|
188 |
xmlNodeSetContent( pSubNode, BAD_CAST result ); |
---|
189 |
free( result ); |
---|
190 |
} |
---|
191 |
} |
---|
192 |
} |
---|
193 |
} |
---|
194 |
|
---|
195 |
xmlAddChild( pDeviceNode, pDevDesc ); |
---|
196 |
} |
---|
197 |
if ( ( !xmlStrcmp( pCur->name, ( const xmlChar * ) "StreamFormats" ) ) ) { |
---|
198 |
xmlNodePtr pDevDesc = xmlCopyNode( pCur, 1 ); |
---|
199 |
if ( !pDevDesc ) { |
---|
200 |
debugError( "addXmlDescription: Could not copy node 'StreamFormats'\n" ); |
---|
201 |
xmlFreeDoc( pDoc ); |
---|
202 |
free( pFilename ); |
---|
203 |
return false; |
---|
204 |
} |
---|
205 |
xmlAddChild( pDeviceNode, pDevDesc ); |
---|
206 |
} |
---|
207 |
|
---|
208 |
pCur = pCur->next; |
---|
209 |
} |
---|
210 |
} |
---|
211 |
|
---|
212 |
xmlFreeDoc( pDoc ); |
---|
213 |
free( pFilename ); |
---|
214 |
|
---|
215 |
return true; |
---|
216 |
} |
---|
217 |
|
---|
218 |
bool |
---|
219 |
AvDevice::prepare() { |
---|
220 |
|
---|
221 |
return true; |
---|
222 |
} |
---|
223 |
|
---|
224 |
} |
---|