root/branches/streaming-rework/src/libfreebobavc/avc_extended_stream_format.cpp

Revision 413, 10.5 kB (checked in by pieterpalmers, 17 years ago)

- moved all generic IEEE1394 classes into libieee1394

src/libieee1394/ieee1394service.h
src/libieee1394/csr1212.h
src/libieee1394/configrom.cpp
src/libieee1394/configrom.h
src/libieee1394/ieee1394service.cpp
src/libieee1394/csr1212.c

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