1 |
/* |
---|
2 |
* Copyright (C) 2005-2008 by Daniel Wagner |
---|
3 |
* |
---|
4 |
* This file is part of FFADO |
---|
5 |
* FFADO = Free Firewire (pro-)audio drivers for linux |
---|
6 |
* |
---|
7 |
* FFADO is based upon FreeBoB |
---|
8 |
* |
---|
9 |
* This program is free software: you can redistribute it and/or modify |
---|
10 |
* it under the terms of the GNU General Public License as published by |
---|
11 |
* the Free Software Foundation, either version 2 of the License, or |
---|
12 |
* (at your option) version 3 of the License. |
---|
13 |
* |
---|
14 |
* This program is distributed in the hope that it will be useful, |
---|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 |
* GNU General Public License for more details. |
---|
18 |
* |
---|
19 |
* You should have received a copy of the GNU General Public License |
---|
20 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
21 |
* |
---|
22 |
*/ |
---|
23 |
|
---|
24 |
#include "avc_extended_stream_format.h" |
---|
25 |
#include "libutil/cmd_serialize.h" |
---|
26 |
#include "libieee1394/ieee1394service.h" |
---|
27 |
|
---|
28 |
#include <netinet/in.h> |
---|
29 |
|
---|
30 |
namespace AVC { |
---|
31 |
|
---|
32 |
/////////////////////////////////////////////////////////// |
---|
33 |
std::ostream& operator<<( std::ostream& stream, StreamFormatInfo info ) |
---|
34 |
{ |
---|
35 |
/* stream << info.m_freq << " Hz ("; |
---|
36 |
if ( info.m_format ) { |
---|
37 |
stream << "sync "; |
---|
38 |
} else { |
---|
39 |
stream << "compound "; |
---|
40 |
} |
---|
41 |
stream << "stream, "; |
---|
42 |
stream << "audio channels: " << info.m_audioChannels |
---|
43 |
<< ", midi channels: " << info.m_midiChannels << ")"; |
---|
44 |
*/ |
---|
45 |
stream << " NbChannels " << (int)info.m_numberOfChannels << ", Format " << (int)info.m_streamFormat; |
---|
46 |
return stream; |
---|
47 |
} |
---|
48 |
|
---|
49 |
StreamFormatInfo::StreamFormatInfo() |
---|
50 |
: IBusData() |
---|
51 |
{ |
---|
52 |
} |
---|
53 |
|
---|
54 |
bool |
---|
55 |
StreamFormatInfo::serialize( Util::Cmd::IOSSerialize& se ) |
---|
56 |
{ |
---|
57 |
se.write( m_numberOfChannels, "StreamFormatInfo numberOfChannels" ); |
---|
58 |
se.write( m_streamFormat, "StreamFormatInfo streamFormat" ); |
---|
59 |
return true; |
---|
60 |
} |
---|
61 |
|
---|
62 |
bool |
---|
63 |
StreamFormatInfo::deserialize( Util::Cmd::IISDeserialize& de ) |
---|
64 |
{ |
---|
65 |
de.read( &m_numberOfChannels ); |
---|
66 |
de.read( &m_streamFormat ); |
---|
67 |
return true; |
---|
68 |
} |
---|
69 |
|
---|
70 |
StreamFormatInfo* |
---|
71 |
StreamFormatInfo::clone() const |
---|
72 |
{ |
---|
73 |
return new StreamFormatInfo( *this ); |
---|
74 |
} |
---|
75 |
|
---|
76 |
//////////////////////////////////////////////////////////// |
---|
77 |
|
---|
78 |
FormatInformationStreamsSync::FormatInformationStreamsSync() |
---|
79 |
: FormatInformationStreams() |
---|
80 |
, m_reserved0( 0xff ) |
---|
81 |
, m_samplingFrequency( eSF_DontCare ) |
---|
82 |
, m_rateControl( eRC_DontCare ) |
---|
83 |
, m_reserved1( 0xff ) |
---|
84 |
{ |
---|
85 |
} |
---|
86 |
|
---|
87 |
bool |
---|
88 |
FormatInformationStreamsSync::serialize( Util::Cmd::IOSSerialize& se ) |
---|
89 |
{ |
---|
90 |
se.write( m_reserved0, "FormatInformationStreamsSync reserved" ); |
---|
91 |
|
---|
92 |
// we have to clobber some bits |
---|
93 |
byte_t operand = ( m_samplingFrequency << 4 ) | 0x0e; |
---|
94 |
if ( m_rateControl == eRC_DontCare) { |
---|
95 |
operand |= 0x1; |
---|
96 |
} |
---|
97 |
se.write( operand, "FormatInformationStreamsSync sampling frequency and rate control" ); |
---|
98 |
|
---|
99 |
se.write( m_reserved1, "FormatInformationStreamsSync reserved" ); |
---|
100 |
return true; |
---|
101 |
} |
---|
102 |
|
---|
103 |
bool |
---|
104 |
FormatInformationStreamsSync::deserialize( Util::Cmd::IISDeserialize& de ) |
---|
105 |
{ |
---|
106 |
de.read( &m_reserved0 ); |
---|
107 |
|
---|
108 |
byte_t operand; |
---|
109 |
de.read( &operand ); |
---|
110 |
m_samplingFrequency = operand >> 4; |
---|
111 |
m_rateControl = operand & 0x01; |
---|
112 |
|
---|
113 |
de.read( &m_reserved1 ); |
---|
114 |
return true; |
---|
115 |
} |
---|
116 |
|
---|
117 |
FormatInformationStreamsSync* |
---|
118 |
FormatInformationStreamsSync::clone() const |
---|
119 |
{ |
---|
120 |
return new FormatInformationStreamsSync( *this ); |
---|
121 |
} |
---|
122 |
|
---|
123 |
//////////////////////////////////////////////////////////// |
---|
124 |
std::ostream& operator<<( std::ostream& stream, FormatInformationStreamsCompound info ) |
---|
125 |
{ |
---|
126 |
stream << (int)info.m_samplingFrequency << " Hz (rate control: "; |
---|
127 |
stream << (int)info.m_rateControl << ")" << std::endl; |
---|
128 |
|
---|
129 |
for ( FormatInformationStreamsCompound::StreamFormatInfoVector::iterator it = info.m_streamFormatInfos.begin(); |
---|
130 |
it != info.m_streamFormatInfos.end(); |
---|
131 |
++it ) |
---|
132 |
{ |
---|
133 |
StreamFormatInfo* sfi=*it; |
---|
134 |
stream << " > " << *sfi << std::endl; |
---|
135 |
} |
---|
136 |
|
---|
137 |
return stream; |
---|
138 |
} |
---|
139 |
|
---|
140 |
FormatInformationStreamsCompound::FormatInformationStreamsCompound() |
---|
141 |
: FormatInformationStreams() |
---|
142 |
, m_samplingFrequency( eSF_DontCare ) |
---|
143 |
, m_rateControl( eRC_DontCare ) |
---|
144 |
, m_numberOfStreamFormatInfos( 0 ) |
---|
145 |
{ |
---|
146 |
} |
---|
147 |
|
---|
148 |
FormatInformationStreamsCompound::~FormatInformationStreamsCompound() |
---|
149 |
{ |
---|
150 |
for ( StreamFormatInfoVector::iterator it = m_streamFormatInfos.begin(); |
---|
151 |
it != m_streamFormatInfos.end(); |
---|
152 |
++it ) |
---|
153 |
{ |
---|
154 |
delete *it; |
---|
155 |
} |
---|
156 |
} |
---|
157 |
|
---|
158 |
bool |
---|
159 |
FormatInformationStreamsCompound::serialize( Util::Cmd::IOSSerialize& se ) |
---|
160 |
{ |
---|
161 |
se.write( m_samplingFrequency, "FormatInformationStreamsCompound samplingFrequency" ); |
---|
162 |
se.write( m_rateControl, "FormatInformationStreamsCompound rateControl" ); |
---|
163 |
se.write( m_numberOfStreamFormatInfos, "FormatInformationStreamsCompound numberOfStreamFormatInfos" ); |
---|
164 |
for ( StreamFormatInfoVector::iterator it = m_streamFormatInfos.begin(); |
---|
165 |
it != m_streamFormatInfos.end(); |
---|
166 |
++it ) |
---|
167 |
{ |
---|
168 |
( *it )->serialize( se ); |
---|
169 |
} |
---|
170 |
return true; |
---|
171 |
} |
---|
172 |
|
---|
173 |
bool |
---|
174 |
FormatInformationStreamsCompound::deserialize( Util::Cmd::IISDeserialize& de ) |
---|
175 |
{ |
---|
176 |
de.read( &m_samplingFrequency ); |
---|
177 |
de.read( &m_rateControl ); |
---|
178 |
de.read( &m_numberOfStreamFormatInfos ); |
---|
179 |
for ( int i = 0; i < m_numberOfStreamFormatInfos; ++i ) { |
---|
180 |
StreamFormatInfo* streamFormatInfo = new StreamFormatInfo; |
---|
181 |
if ( !streamFormatInfo->deserialize( de ) ) { |
---|
182 |
return false; |
---|
183 |
} |
---|
184 |
m_streamFormatInfos.push_back( streamFormatInfo ); |
---|
185 |
} |
---|
186 |
return true; |
---|
187 |
} |
---|
188 |
|
---|
189 |
FormatInformationStreamsCompound* |
---|
190 |
FormatInformationStreamsCompound::clone() const |
---|
191 |
{ |
---|
192 |
return new FormatInformationStreamsCompound( *this ); |
---|
193 |
} |
---|
194 |
|
---|
195 |
//////////////////////////////////////////////////////////// |
---|
196 |
|
---|
197 |
FormatInformation::FormatInformation() |
---|
198 |
: IBusData() |
---|
199 |
, m_root( eFHR_Invalid ) |
---|
200 |
, m_level1( eFHL1_AUDIOMUSIC_DONT_CARE ) |
---|
201 |
, m_level2( eFHL2_AM824_DONT_CARE ) |
---|
202 |
, m_streams( 0 ) |
---|
203 |
{ |
---|
204 |
} |
---|
205 |
|
---|
206 |
FormatInformation::FormatInformation( const FormatInformation& rhs ) |
---|
207 |
: IBusData() |
---|
208 |
, m_root( rhs.m_root ) |
---|
209 |
, m_level1( rhs.m_level1 ) |
---|
210 |
, m_level2( rhs.m_level2 ) |
---|
211 |
, m_streams( 0 ) |
---|
212 |
{ |
---|
213 |
if ( rhs.m_streams ) { |
---|
214 |
m_streams = dynamic_cast<FormatInformationStreams*>( rhs.m_streams->clone() ); |
---|
215 |
} |
---|
216 |
} |
---|
217 |
|
---|
218 |
FormatInformation::~FormatInformation() |
---|
219 |
{ |
---|
220 |
delete m_streams; |
---|
221 |
m_streams = 0; |
---|
222 |
} |
---|
223 |
|
---|
224 |
bool |
---|
225 |
FormatInformation::serialize( Util::Cmd::IOSSerialize& se ) |
---|
226 |
{ |
---|
227 |
if ( m_root != eFHR_Invalid ) { |
---|
228 |
se.write( m_root, "FormatInformation hierarchy root" ); |
---|
229 |
if ( m_level1 != eFHL1_AUDIOMUSIC_DONT_CARE ) { |
---|
230 |
se.write( m_level1, "FormatInformation hierarchy level 1" ); |
---|
231 |
if ( m_level2 != eFHL2_AM824_DONT_CARE ) { |
---|
232 |
se.write( m_level2, "FormatInformation hierarchy level 2" ); |
---|
233 |
} |
---|
234 |
} |
---|
235 |
} |
---|
236 |
if ( m_streams ) { |
---|
237 |
return m_streams->serialize( se ); |
---|
238 |
} |
---|
239 |
return true; |
---|
240 |
} |
---|
241 |
|
---|
242 |
bool |
---|
243 |
FormatInformation::deserialize( Util::Cmd::IISDeserialize& de ) |
---|
244 |
{ |
---|
245 |
bool result = false; |
---|
246 |
|
---|
247 |
delete m_streams; |
---|
248 |
m_streams = 0; |
---|
249 |
|
---|
250 |
// this code just parses BeBoB replies. |
---|
251 |
de.read( &m_root ); |
---|
252 |
|
---|
253 |
// just parse an audio and music hierarchy |
---|
254 |
if ( m_root == eFHR_AudioMusic ) { |
---|
255 |
de.read( &m_level1 ); |
---|
256 |
|
---|
257 |
switch ( m_level1 ) { |
---|
258 |
case eFHL1_AUDIOMUSIC_AM824: |
---|
259 |
{ |
---|
260 |
// note: compound streams don't have a second level |
---|
261 |
de.read( &m_level2 ); |
---|
262 |
|
---|
263 |
if (m_level2 == eFHL2_AM824_SYNC_STREAM ) { |
---|
264 |
m_streams = new FormatInformationStreamsSync(); |
---|
265 |
result = m_streams->deserialize( de ); |
---|
266 |
} else { |
---|
267 |
// anything but the sync stream workds currently. |
---|
268 |
printf( "could not parse format information. (format hierarchy level 2 not recognized)\n" ); |
---|
269 |
} |
---|
270 |
} |
---|
271 |
break; |
---|
272 |
case eFHL1_AUDIOMUSIC_AM824_COMPOUND: |
---|
273 |
{ |
---|
274 |
m_streams = new FormatInformationStreamsCompound(); |
---|
275 |
result = m_streams->deserialize( de ); |
---|
276 |
} |
---|
277 |
break; |
---|
278 |
default: |
---|
279 |
printf( "could not parse format information. (format hierarchy level 1 not recognized)\n" ); |
---|
280 |
} |
---|
281 |
} |
---|
282 |
|
---|
283 |
return result; |
---|
284 |
} |
---|
285 |
|
---|
286 |
FormatInformation* |
---|
287 |
FormatInformation::clone() const |
---|
288 |
{ |
---|
289 |
return new FormatInformation( *this ); |
---|
290 |
} |
---|
291 |
|
---|
292 |
//////////////////////////////////////////////////////////// |
---|
293 |
|
---|
294 |
ExtendedStreamFormatCmd::ExtendedStreamFormatCmd( Ieee1394Service& service, |
---|
295 |
ESubFunction eSubFunction ) |
---|
296 |
: AVCCommand( service, AVC1394_STREAM_FORMAT_SUPPORT ) |
---|
297 |
, m_subFunction( eSubFunction ) |
---|
298 |
, m_status( eS_NotUsed ) |
---|
299 |
, m_indexInStreamFormat( 0 ) |
---|
300 |
, m_formatInformation( new FormatInformation ) |
---|
301 |
{ |
---|
302 |
UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 0x00 ); |
---|
303 |
m_plugAddress = new PlugAddress( PlugAddress::ePD_Output, PlugAddress::ePAM_Unit, unitPlugAddress ); |
---|
304 |
} |
---|
305 |
|
---|
306 |
ExtendedStreamFormatCmd::ExtendedStreamFormatCmd( |
---|
307 |
const ExtendedStreamFormatCmd& rhs ) |
---|
308 |
: AVCCommand( rhs ) |
---|
309 |
{ |
---|
310 |
m_subFunction = rhs.m_subFunction; |
---|
311 |
m_plugAddress = new PlugAddress( *rhs.m_plugAddress ); |
---|
312 |
m_formatInformation = |
---|
313 |
new FormatInformation( *rhs.m_formatInformation ); |
---|
314 |
} |
---|
315 |
|
---|
316 |
ExtendedStreamFormatCmd::~ExtendedStreamFormatCmd() |
---|
317 |
{ |
---|
318 |
delete m_plugAddress; |
---|
319 |
m_plugAddress = 0; |
---|
320 |
delete m_formatInformation; |
---|
321 |
m_formatInformation = 0; |
---|
322 |
} |
---|
323 |
|
---|
324 |
bool |
---|
325 |
ExtendedStreamFormatCmd::setPlugAddress( const PlugAddress& plugAddress ) |
---|
326 |
{ |
---|
327 |
delete m_plugAddress; |
---|
328 |
m_plugAddress = plugAddress.clone(); |
---|
329 |
return true; |
---|
330 |
} |
---|
331 |
|
---|
332 |
bool |
---|
333 |
ExtendedStreamFormatCmd::setIndexInStreamFormat( const int index ) |
---|
334 |
{ |
---|
335 |
m_indexInStreamFormat = index; |
---|
336 |
return true; |
---|
337 |
} |
---|
338 |
|
---|
339 |
bool |
---|
340 |
ExtendedStreamFormatCmd::serialize( Util::Cmd::IOSSerialize& se ) |
---|
341 |
{ |
---|
342 |
AVCCommand::serialize( se ); |
---|
343 |
se.write( m_subFunction, "ExtendedStreamFormatCmd subFunction" ); |
---|
344 |
m_plugAddress->serialize( se ); |
---|
345 |
se.write( m_status, "ExtendedStreamFormatCmd status" ); |
---|
346 |
if ( m_subFunction == eSF_ExtendedStreamFormatInformationCommandList ) { |
---|
347 |
se.write( m_indexInStreamFormat, "indexInStreamFormat" ); |
---|
348 |
} |
---|
349 |
m_formatInformation->serialize( se ); |
---|
350 |
return true; |
---|
351 |
} |
---|
352 |
|
---|
353 |
bool |
---|
354 |
ExtendedStreamFormatCmd::deserialize( Util::Cmd::IISDeserialize& de ) |
---|
355 |
{ |
---|
356 |
AVCCommand::deserialize( de ); |
---|
357 |
de.read( &m_subFunction ); |
---|
358 |
m_plugAddress->deserialize( de ); |
---|
359 |
de.read( &m_status ); |
---|
360 |
if ( m_subFunction == eSF_ExtendedStreamFormatInformationCommandList ) { |
---|
361 |
de.read( &m_indexInStreamFormat ); |
---|
362 |
} |
---|
363 |
m_formatInformation->deserialize( de ); |
---|
364 |
return true; |
---|
365 |
} |
---|
366 |
|
---|
367 |
ExtendedStreamFormatCmd::EStatus |
---|
368 |
ExtendedStreamFormatCmd::getStatus() |
---|
369 |
{ |
---|
370 |
EStatus status = static_cast<EStatus>( m_status ); |
---|
371 |
return status; |
---|
372 |
} |
---|
373 |
|
---|
374 |
FormatInformation* |
---|
375 |
ExtendedStreamFormatCmd::getFormatInformation() |
---|
376 |
{ |
---|
377 |
return m_formatInformation; |
---|
378 |
} |
---|
379 |
|
---|
380 |
ExtendedStreamFormatCmd::index_in_stream_format_t |
---|
381 |
ExtendedStreamFormatCmd::getIndex() |
---|
382 |
{ |
---|
383 |
return m_indexInStreamFormat; |
---|
384 |
} |
---|
385 |
|
---|
386 |
bool |
---|
387 |
ExtendedStreamFormatCmd::setSubFunction( ESubFunction subFunction ) |
---|
388 |
{ |
---|
389 |
m_subFunction = subFunction; |
---|
390 |
return true; |
---|
391 |
} |
---|
392 |
|
---|
393 |
} |
---|