root/branches/streaming-rework/src/bounce/bounce_avdevice.cpp

Revision 407, 11.4 kB (checked in by pieterpalmers, 16 years ago)

- Changed the way the device class configure options are handled. Now they are handled in the makefiles instead of the source files. The only source file that still contains the #ifdef's is devicemanager.cpp, to conditionally include the device class include files and to conditionally probe the classes that might be supported.
- added a configure option to disable the compilation of the test programs in tests/
- cleaned up the ADMTP transmit streamprocessor. Now it sends silenced packets when in the disabled state, instead of no-data packets
- added a getNodeID() to ieee1394service
- made comments in ieee1394service.h doxygen compliant

Line 
1 /* bounce_avdevice.cpp
2  * Copyright (C) 2006 by Pieter Palmers
3  * Copyright (C) 2006 by Daniel Wagner
4  *
5  * This file is part of FreeBoB.
6  *
7  * FreeBoB is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  * FreeBoB is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with FreeBoB; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19  * MA 02111-1307 USA.
20  */
21 #include "bounce/bounce_avdevice.h"
22 #include "configrom.h"
23
24 #include "libfreebobavc/avc_plug_info.h"
25 #include "libfreebobavc/avc_extended_plug_info.h"
26 #include "libfreebobavc/avc_subunit_info.h"
27 #include "libfreebobavc/avc_extended_stream_format.h"
28 #include "libfreebobavc/avc_serialize.h"
29 #include "libfreebobavc/ieee1394service.h"
30 #include "libfreebobavc/avc_definitions.h"
31
32 #include "debugmodule/debugmodule.h"
33
34 #include <iostream>
35 #include <sstream>
36 #include <stdint.h>
37
38 #include <string>
39 #include <netinet/in.h>
40
41 namespace Bounce {
42
43 // to define the supported devices
44 static VendorModelEntry supportedDeviceList[] =
45 {
46     {0x0B0001, 0x0B0001, 0x0B0001, "FreeBoB", "Bounce"},
47 };
48
49 IMPL_DEBUG_MODULE( BounceDevice, BounceDevice, DEBUG_LEVEL_VERBOSE );
50
51
52 BounceDevice::BounceDevice( std::auto_ptr< ConfigRom >( configRom ),
53                             Ieee1394Service& ieee1394service,
54                             int nodeId,
55                             int verboseLevel )
56     : m_configRom( configRom )
57     , m_1394Service( &ieee1394service )
58     , m_nodeId( nodeId )
59     , m_verboseLevel( verboseLevel )
60     , m_samplerate (44100)
61     , m_model( NULL )
62     , m_id(0)
63     , m_receiveProcessor ( 0 )
64     , m_receiveProcessorBandwidth ( -1 )
65     , m_transmitProcessor ( 0 )
66     , m_transmitProcessorBandwidth ( -1 )
67 {
68     setDebugLevel( verboseLevel );
69
70     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Bounce::BounceDevice (NodeID %d)\n",
71                  nodeId );
72 }
73
74 BounceDevice::~BounceDevice()
75 {
76
77 }
78
79 ConfigRom&
80 BounceDevice::getConfigRom() const
81 {
82     return *m_configRom;
83 }
84
85 bool
86 BounceDevice::probe( ConfigRom& configRom )
87 {
88 //     unsigned int vendorId = configRom.getNodeVendorId();
89     unsigned int modelId = configRom.getModelId();
90     unsigned int unitSpecifierId = configRom.getUnitSpecifierId();
91
92     for ( unsigned int i = 0;
93           i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) );
94           ++i )
95     {
96         if (
97 //             ( supportedDeviceList[i].vendor_id == vendorId )
98              ( supportedDeviceList[i].model_id == modelId )
99              && ( supportedDeviceList[i].unit_specifier_id == unitSpecifierId )
100            )
101         {
102             return true;
103         }
104     }
105
106     return false;
107 }
108
109 bool
110 BounceDevice::discover()
111 {
112 //      unsigned int resp_len=0;
113 //      quadlet_t request[6];
114 //      quadlet_t *resp;
115
116 //     unsigned int vendorId = m_configRom->getNodeVendorId();
117     unsigned int modelId = m_configRom->getModelId();
118     unsigned int unitSpecifierId = m_configRom->getUnitSpecifierId();
119
120     for ( unsigned int i = 0;
121           i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) );
122           ++i )
123     {
124         if ( //( supportedDeviceList[i].vendor_id == vendorId )
125              ( supportedDeviceList[i].model_id == modelId )
126              && ( supportedDeviceList[i].unit_specifier_id == unitSpecifierId )
127            )
128         {
129             m_model = &(supportedDeviceList[i]);
130         }
131     }
132
133     if (m_model != NULL) {
134         debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n",
135                 m_model->vendor_name, m_model->model_name);
136         return true;
137     }
138    
139     debugOutput( DEBUG_LEVEL_VERBOSE, "Discovering...\n" );
140
141         std::string vendor=std::string(FREEBOB_BOUNCE_SERVER_VENDORNAME);
142         std::string model=std::string(FREEBOB_BOUNCE_SERVER_MODELNAME);
143
144         if (!(m_configRom->getVendorName().compare(0,vendor.length(),vendor,0,vendor.length())==0)
145             || !(m_configRom->getModelName().compare(0,model.length(),model,0,model.length())==0)) {
146                 return false;
147         }
148 /*
149 // AVC1394_COMMAND_INPUT_PLUG_SIGNAL_FORMAT
150         request[0] = htonl( AVC1394_CTYPE_STATUS | (AVC1394_SUBUNIT_TYPE_FREEBOB_BOUNCE_SERVER << 19) | (0 << 16)
151                         | AVC1394_COMMAND_INPUT_PLUG_SIGNAL_FORMAT | 0x00);
152
153         request[1] =  0xFFFFFFFF;
154         resp = m_1394Service->transactionBlock( m_nodeId,
155                                                        request,
156                                                        2,
157                                                                &resp_len );
158 //      hexDump((unsigned char *)request,6*4);
159         if(resp) {
160                 char *buffer=(char *)&resp[1];
161                 resp[resp_len-1]=0;
162                 xmlDescription=buffer;
163 //              hexDump((unsigned char *)resp,6*4);
164         }
165 */
166         return true;
167 }
168
169 int BounceDevice::getSamplingFrequency( ) {
170     return m_samplerate;
171 }
172
173 bool BounceDevice::setSamplingFrequency( ESamplingFrequency samplingFrequency ) {
174     int retval=convertESamplingFrequency( samplingFrequency );
175     if (retval) {
176         m_samplerate=retval;
177         return true;
178     } else return false;
179 }
180
181 bool BounceDevice::setId( unsigned int id) {
182     debugOutput( DEBUG_LEVEL_VERBOSE, "Set id to %d...\n", id);
183     m_id=id;
184     return true;
185 }
186
187 void
188 BounceDevice::showDevice() const
189 {
190     debugOutput(DEBUG_LEVEL_NORMAL, "\nI am the bouncedevice, the bouncedevice I am...\n" );
191     debugOutput(DEBUG_LEVEL_NORMAL, "Vendor            :  %s\n", m_configRom->getVendorName().c_str());
192     debugOutput(DEBUG_LEVEL_NORMAL, "Model             :  %s\n", m_configRom->getModelName().c_str());
193     debugOutput(DEBUG_LEVEL_NORMAL, "Vendor Name       :  %s\n", m_model->vendor_name);
194     debugOutput(DEBUG_LEVEL_NORMAL, "Model Name        :  %s\n", m_model->model_name);
195     debugOutput(DEBUG_LEVEL_NORMAL, "Node              :  %d\n", m_nodeId);
196     debugOutput(DEBUG_LEVEL_NORMAL, "GUID              :  0x%016llX\n", m_configRom->getGuid());
197     debugOutput(DEBUG_LEVEL_NORMAL, "AVC test response :  %s\n", xmlDescription.c_str());
198     debugOutput(DEBUG_LEVEL_NORMAL, "\n" );
199 }
200
201 bool
202 BounceDevice::addXmlDescription( xmlNodePtr deviceNode )
203 {
204
205     return false;
206
207 }
208
209 #define BOUNCE_NR_OF_CHANNELS 2
210
211 bool
212 BounceDevice::addPortsToProcessor(
213         FreebobStreaming::StreamProcessor *processor,
214         FreebobStreaming::AmdtpAudioPort::E_Direction direction) {
215
216     debugOutput(DEBUG_LEVEL_VERBOSE,"Adding ports to processor\n");
217
218     int i=0;
219     for (i=0;i<BOUNCE_NR_OF_CHANNELS;i++) {
220         char *buff;
221         asprintf(&buff,"dev%d%s_Port%d",m_id,direction==FreebobStreaming::AmdtpAudioPort::E_Playback?"p":"c",i);
222
223         FreebobStreaming::Port *p=NULL;
224         p=new FreebobStreaming::AmdtpAudioPort(
225                 buff,
226                 direction,
227                 // \todo: streaming backend expects indexing starting from 0
228                 // but bebob reports it starting from 1. Decide where
229                 // and how to handle this (pp: here)
230                 i,
231                 0,
232                 FreebobStreaming::AmdtpPortInfo::E_MBLA,
233                 0
234         );
235
236         if (!p) {
237             debugOutput(DEBUG_LEVEL_VERBOSE, "Skipped port %s\n",buff);
238         } else {
239
240             if (!processor->addPort(p)) {
241                 debugWarning("Could not register port with stream processor\n");
242                 free(buff);
243                 return false;
244             } else {
245                 debugOutput(DEBUG_LEVEL_VERBOSE, "Added port %s\n",buff);
246             }
247         }
248
249         free(buff);
250
251      }
252
253         return true;
254 }
255
256 bool
257 BounceDevice::prepare() {
258
259     debugOutput(DEBUG_LEVEL_NORMAL, "Preparing BounceDevice...\n" );
260
261         m_receiveProcessor=new FreebobStreaming::AmdtpReceiveStreamProcessor(
262                                  m_1394Service->getPort(),
263                                  m_samplerate,
264                                  BOUNCE_NR_OF_CHANNELS);
265
266         if(!m_receiveProcessor->init()) {
267                 debugFatal("Could not initialize receive processor!\n");
268                 return false;
269
270         }
271
272         if (!addPortsToProcessor(m_receiveProcessor,
273                 FreebobStreaming::AmdtpAudioPort::E_Capture)) {
274                 debugFatal("Could not add ports to processor!\n");
275                 return false;
276         }
277
278         // do the transmit processor
279         m_transmitProcessor=new FreebobStreaming::AmdtpTransmitStreamProcessor(
280                                  m_1394Service->getPort(),
281                                  m_samplerate,
282                                  BOUNCE_NR_OF_CHANNELS);
283
284         m_transmitProcessor->setVerboseLevel(getDebugLevel());
285
286         if(!m_transmitProcessor->init()) {
287                 debugFatal("Could not initialize transmit processor!\n");
288                 return false;
289
290         }
291
292         if (!addPortsToProcessor(m_transmitProcessor,
293                 FreebobStreaming::AmdtpAudioPort::E_Playback)) {
294                 debugFatal("Could not add ports to processor!\n");
295                 return false;
296         }
297
298         return true;
299 }
300
301 int
302 BounceDevice::getStreamCount() {
303         return 2; // one receive, one transmit
304 }
305
306 FreebobStreaming::StreamProcessor *
307 BounceDevice::getStreamProcessorByIndex(int i) {
308         switch (i) {
309         case 0:
310                 return m_receiveProcessor;
311         case 1:
312                 return m_transmitProcessor;
313         default:
314                 return NULL;
315         }
316         return 0;
317 }
318
319 int
320 BounceDevice::startStreamByIndex(int i) {
321 //      int iso_channel=0;
322 //      int plug=0;
323 //      int hostplug=-1;
324 //
325         switch (i) {
326         case 0:
327 //              // do connection management: make connection
328 //              iso_channel = iec61883_cmp_connect(
329 //                      m_1394Service->getHandle(),
330 //                      m_nodeId | 0xffc0,
331 //                      &plug,
332 //                      raw1394_get_local_id (m_1394Service->getHandle()),
333 //                      &hostplug,
334 //                      &m_receiveProcessorBandwidth);
335 //
336 //              // set the channel obtained by the connection management
337     #warning TEST CODE FOR BOUNCE DEVICE !!
338         if (m_configRom->getNodeId()==0) {
339             m_receiveProcessor->setChannel(1);
340         } else {
341             m_receiveProcessor->setChannel(0);
342         }
343                 break;
344         case 1:
345 //              // do connection management: make connection
346 //              iso_channel = iec61883_cmp_connect(
347 //                      m_1394Service->getHandle(),
348 //                      raw1394_get_local_id (m_1394Service->getHandle()),
349 //                      &hostplug,
350 //                      m_nodeId | 0xffc0,
351 //                      &plug,
352 //                      &m_transmitProcessorBandwidth);
353 //
354 //              // set the channel obtained by the connection management
355 // //           m_receiveProcessor2->setChannel(iso_channel);
356     #warning TEST CODE FOR BOUNCE DEVICE !!
357         if (m_configRom->getNodeId()==0) {
358             m_transmitProcessor->setChannel(0);
359         } else {
360             m_transmitProcessor->setChannel(1);
361         }
362                 break;
363         default:
364                 return -1;
365         }
366
367         return 0;
368
369 }
370
371 int
372 BounceDevice::stopStreamByIndex(int i) {
373         // do connection management: break connection
374
375 //      int plug=0;
376 //      int hostplug=-1;
377 //
378 //      switch (i) {
379 //      case 0:
380 //              // do connection management: break connection
381 //              iec61883_cmp_disconnect(
382 //                      m_1394Service->getHandle(),
383 //                      m_nodeId | 0xffc0,
384 //                      plug,
385 //                      raw1394_get_local_id (m_1394Service->getHandle()),
386 //                      hostplug,
387 //                      m_receiveProcessor->getChannel(),
388 //                      m_receiveProcessorBandwidth);
389 //
390 //              break;
391 //      case 1:
392 //              // do connection management: break connection
393 //              iec61883_cmp_disconnect(
394 //                      m_1394Service->getHandle(),
395 //                      raw1394_get_local_id (m_1394Service->getHandle()),
396 //                      hostplug,
397 //                      m_nodeId | 0xffc0,
398 //                      plug,
399 //                      m_transmitProcessor->getChannel(),
400 //                      m_transmitProcessorBandwidth);
401 //
402 //              // set the channel obtained by the connection management
403 // //           m_receiveProcessor2->setChannel(iso_channel);
404 //              break;
405 //      default:
406 //              return 0;
407 //      }
408
409         return 0;
410 }
411
412 } // namespace
Note: See TracBrowser for help on using the browser.