root/trunk/libffado/src/ffadodevice.cpp

Revision 1498, 7.2 kB (checked in by ppalmers, 15 years ago)

Merge all changes from 2.0 branch into trunk (since r1361). This _should_ contain all forward merges done in the mean time. At this moment in time both branches should be in sync.

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