root/trunk/libffado/src/bebob/maudio/special_avdevice.cpp

Revision 2691, 5.6 kB (checked in by jwoithe, 7 years ago)

Initial attempt to address deprecation of auto_ptr.

C++11 deprecates auto_ptr, and gcc6 (and later versions) print compile time
warnings to this effect whenever it is encountered in the source. The
replacement type is either shared_ptr or unique_ptr depending on the usage.
For almost all usages within FFADO it seems unique_ptr could be the
appropriate choice, but the symantics are a little different to auto_ptr.
Shared_ptr on the other hand can be a drop-in replacement, although it comes
with considerable overheads which unique_ptr avoids. In the context of the
current usage, the extra overhead incurred is not critical.

The code-base cannot at this time change unconditionally to shared_ptr and
unique_ptr because these are not available in gcc4 unless "--std=c++11" is
given. When gcc4 is used certain older versions of dependent libraries must
be used and these in turn will cause compile failures in their header files
if "--std=c++11" is used (libxml++ being an example). At present there are
sufficient users of FFADO still on gcc4 to justify maintaining compatibility
with that gcc version.

The approach adopted at present is to define ffado_smartptr to be either
auto_ptr (if c++11 is not in use) or shared_ptr if it is. All auto_ptr
instances are then changed to ffado_smartptr. This should allow FFADO to be
compiled without errors or warnings on systems using gcc4 and above. Gcc6
defaults to the c++14 standard, so ffado_smartptr will be shared_ptr in that
case; thus the warnings will be avoided.

In time, once gcc4 drops out of common use, the ffado_smartptr instances can
be progressively migrated to unique_ptr or shared_ptr as is appropriate. It
has been pointed out in the ffado-devel mailing list by Jano Svitok (2 May
2017, subject "smart pointers Was: [FFADO-devel] Liquid Saffire 56") that
bebob_dl_mgr.cpp could use unique_ptr. shared_ptr should be ok in other
auto_ptr sites, but futher analysis may show that at least some of them can
use unique_ptr.

The addressing of the auto_ptr issue was prompted by Xavier Forestier's
patch set submitted to ffado-devel in November 2016.

Line 
1 /*
2  * Copyright (C) 2014      by Takashi Sakamoto
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 "libutil/Configuration.h"
26 #include "libutil/ByteSwap.h"
27 #include "libutil/SystemTimeSource.h"
28
29 #include <libraw1394/csr.h>
30 #include <libieee1394/IEC61883.h>
31
32 #include "bebob/maudio/special_avdevice.h"
33
34 namespace BeBoB {
35 namespace MAudio {
36 namespace Special {
37
38 Device::Device(DeviceManager& d, ffado_smartptr<ConfigRom>(configRom))
39     : BeBoB::Device(d, configRom)
40 {
41     is1814 = (getConfigRom().getModelId() == 0x00010071);
42
43     debugOutput(DEBUG_LEVEL_VERBOSE, "Created BeBoB::MAudio::Device (NodeID %d)\n",
44                 getConfigRom().getNodeId());
45     updateClockSources();
46 }
47
48 void Device::showDevice()
49 {
50     debugOutput(DEBUG_LEVEL_NORMAL, "This is a BeBoB::MAudio::Device\n");
51 }
52
53 /*
54  * Discoveing plugs:
55  *  The firmware can't respond any commands related to plug info.
56  */
57 bool Device::discover()
58 {
59     /* keep track of the config id of this discovery */
60     m_last_discovery_config_id = getConfigurationId();
61
62     return true;
63 }
64
65 /* don't lock to prevent from streaming */
66 bool Device::lock()
67 {
68         return false;
69 }
70 bool Device::Unlock()
71 {
72         return false;
73 }
74
75 /* don't cache */
76 bool Device::loadFromCache()
77 {
78         return buildMixer();
79 }
80 bool Device::saveCache()
81 {
82         return true;
83 }
84
85 bool Device::buildMixer()
86 {
87     debugOutput(DEBUG_LEVEL_VERBOSE, "Building a maudio special mixer...\n");
88
89     delete m_special_mixer;
90
91     m_special_mixer = new Mixer(*this);
92     if (m_special_mixer)
93         m_special_mixer->setVerboseLevel(getDebugLevel());
94
95     return (m_special_mixer != NULL);
96 }
97
98 bool Device::destroyMixer()
99 {
100     delete m_special_mixer;
101     return true;
102 }
103
104 /*
105  * Sampling frequency support:
106  *  set: Input/Output Signal Format command
107  *  get: Input Signal Format command (or metering information)
108  *
109  * TODO
110  */
111 std::vector<int> Device::getSupportedSamplingFrequencies()
112 {
113     std::vector<int> freqs;
114     freqs.push_back(0);
115     return freqs;
116 }
117 bool Device::supportsSamplingFrequency(int s)
118 {
119     return true;
120 }
121 int Device::getSamplingFrequency()
122 {
123     return 0;
124 }
125
126 /*
127  * Clock Source support:
128  * TODO: use ALSA control interface
129  *
130  */
131 void Device::updateClockSources()
132 {
133     m_fixed_clksrc.type = FFADODevice::eCT_Internal;
134     m_fixed_clksrc.active = true;
135     m_fixed_clksrc.valid = true;
136     m_fixed_clksrc.locked = true;
137     m_fixed_clksrc.id = 0;
138     m_fixed_clksrc.slipping = false;
139     m_fixed_clksrc.description = "Controlled by ALSA";
140 }
141 FFADODevice::ClockSourceVector
142 Device::getSupportedClockSources()
143 {
144     FFADODevice::ClockSourceVector r;
145     r.push_back(m_fixed_clksrc);
146     return r;
147 }
148 FFADODevice::ClockSource
149 Device::getActiveClockSource()
150 {
151     return m_fixed_clksrc;
152 }
153 bool
154 Device::setActiveClockSource(ClockSource s)
155 {
156     return true;
157 }
158
159 /*
160  * Streaming State:
161  *  The firmware can't respond against frequent requests.
162  * TODO: how to void frequent transaction?
163  */
164 enum FFADODevice::eStreamingState
165 Device::getStreamingState()
166 {
167     return eSS_Both;
168 }
169
170 /*
171  * The firmware can't speak:
172  *  'Extended Plug Info command' (BridgeCo)
173  *  'Connection and Compatibility Management' (1394TA)
174  */
175 uint8_t
176 Device::getConfigurationIdSampleRate()
177 {
178     return 1;
179 }
180 uint8_t
181 Device::getConfigurationIdNumberOfChannel( AVC::PlugAddress::EPlugDirection ePlugDirection )
182 {
183         return 2;
184 }
185 uint16_t
186 Device::getConfigurationIdSyncMode()
187 {
188         return 3;
189 }
190
191 bool Device::readReg(uint64_t offset, uint32_t *data)
192 {
193     Util::MutexLockHelper lock(m_DeviceMutex);
194
195     /* read cache because it's 'write-only' */
196     *data = m_regs[offset / 4];
197     return true;
198 }
199
200 bool Device::writeReg(uint64_t offset, uint32_t data)
201 {
202     int trials;
203     fb_nodeid_t nodeId;
204     fb_nodeaddr_t addr;
205     fb_quadlet_t quad;
206
207     Util::MutexLockHelper lock(m_DeviceMutex);
208
209     nodeId = getNodeId() | 0xffc0;
210     addr = MAUDIO_SPECIFIC_ADDRESS + MAUDIO_CONTROL_OFFSET + offset;
211     quad = CondSwapToBus32(data);
212
213     /* cache because it's 'write-only' */
214     m_regs[offset / 4] = data;
215
216     trials = 0;
217     do {
218         if (get1394Service().write_quadlet(nodeId, addr, quad))
219             break;
220         Util::SystemTimeSource::SleepUsecRelative(100);
221     } while (++trials < 4);
222
223     return true;
224 }
225
226 bool Device::writeBlk(uint64_t offset, unsigned int size, uint32_t *data)
227 {
228     fb_nodeid_t nodeId;
229     fb_nodeaddr_t addr;
230     unsigned int i, length, trials;
231
232     nodeId = getNodeId() | 0xffc0;
233     addr = MAUDIO_SPECIFIC_ADDRESS + MAUDIO_CONTROL_OFFSET + offset;
234     length = size /4;
235
236     for (i = 0; i < length; i++) {
237         /* the device applies the setting even if the device don't respond */
238         m_regs[i] = data[i];
239         data[i] = CondSwapToBus32(data[i]);
240     }
241
242     trials = 0;
243     do {
244         if (get1394Service().write(nodeId, addr, length, (fb_quadlet_t*)data))
245             break;
246         Util::SystemTimeSource::SleepUsecRelative(100);
247     } while (++trials < 4);
248
249     return true;
250 }
251
252 } // namespace Special
253 } // namespace MAudio
254 } // namespace BeBoB
Note: See TracBrowser for help on using the browser.