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

Revision 1215, 6.7 kB (checked in by ppalmers, 13 years ago)

add generic samplerate control (bis)

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 enum FFADODevice::eSyncState
147 FFADODevice::getSyncState( ) {
148     return eSS_Unknown;
149 }
150
151 bool
152 FFADODevice::setId( unsigned int id)
153 {
154     Util::MutexLockHelper lock(m_DeviceMutex);
155     bool retval;
156     // FIXME: decent ID system nescessary
157     std::ostringstream idstr;
158     idstr << "dev" << id;
159     debugOutput( DEBUG_LEVEL_VERBOSE, "Set id to %s...\n", idstr.str().c_str());
160
161     retval=setOption("id",idstr.str());
162     return retval;
163 }
164
165 bool
166 FFADODevice::setNickname( std::string name)
167 {
168     return false;
169 }
170
171 std::string
172 FFADODevice::getNickname()
173 {
174     return "Unknown";
175 }
176
177 void
178 FFADODevice::handleBusReset()
179 {
180     debugOutput( DEBUG_LEVEL_VERBOSE, "Handle bus reset...\n");
181
182     // update the config rom node id
183     sleep(1);
184
185     Util::MutexLockHelper lock(m_DeviceMutex);
186     getConfigRom().setVerboseLevel(getDebugLevel());
187     getConfigRom().updatedNodeId();
188 }
189
190 void
191 FFADODevice::setVerboseLevel(int l)
192 {
193     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l );
194     setDebugLevel(l);
195     m_DeviceMutex.setVerboseLevel(l);
196     getConfigRom().setVerboseLevel(l);
197 }
198
199 void
200 FFADODevice::showDevice()
201 {
202     #ifdef DEBUG
203     Ieee1394Service& s = getConfigRom().get1394Service();
204     debugOutput(DEBUG_LEVEL_NORMAL, "Attached to port.......: %d (%s)\n",
205                                     s.getPort(), s.getPortName().c_str());
206     debugOutput(DEBUG_LEVEL_NORMAL, "Node...................: %d\n", getNodeId());
207     debugOutput(DEBUG_LEVEL_NORMAL, "Vendor name............: %s\n",
208                                     getConfigRom().getVendorName().c_str());
209     debugOutput(DEBUG_LEVEL_NORMAL, "Model name.............: %s\n",
210                                     getConfigRom().getModelName().c_str());
211     debugOutput(DEBUG_LEVEL_NORMAL, "GUID...................: %s\n",
212                                     getConfigRom().getGuidString().c_str());
213
214     std::string id=std::string("dev? [none]");
215     getOption("id", id);
216
217     debugOutput(DEBUG_LEVEL_NORMAL, "Assigned ID....: %s\n", id.c_str());
218
219     flushDebugOutput();
220     #endif
221 }
222
223
224 bool
225 FFADODevice::enableStreaming() {
226     return true;
227 }
228
229 bool
230 FFADODevice::disableStreaming() {
231     return true;
232 }
233
234 const char *
235 FFADODevice::ClockSourceTypeToString(enum eClockSourceType t)
236 {
237     switch(t) {
238         default:            return "Erratic type      ";
239         case eCT_Invalid:   return "Invalid           ";
240         case eCT_Internal:  return "Internal          ";
241         case eCT_1394Bus:   return "1394 Bus          ";
242         case eCT_SytMatch:  return "Compound Syt Match";
243         case eCT_SytStream: return "Sync Syt Match    ";
244         case eCT_WordClock: return "WordClock         ";
245         case eCT_SPDIF:     return "SPDIF             ";
246         case eCT_ADAT:      return "ADAT              ";
247         case eCT_TDIF:      return "TDIF              ";
248         case eCT_AES:       return "AES               ";
249     }
250 }
Note: See TracBrowser for help on using the browser.