root/branches/libffado-2.0/src/ffadodevice.cpp

Revision 1385, 6.9 kB (checked in by ppalmers, 12 years ago)

Implement a mechanism to disable the samplerate and clock source controls while the device is streaming in order to avoid changes that could mess up jack. The saffire pro controls that cause a device reset to
happen are also disabled while streaming is active.

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