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

Revision 404, 10.0 kB (checked in by pieterpalmers, 16 years ago)

- introduce support framework for DICE and Metric Halo
- change probe/discovery code to make adding devices easier
- made conditional compilation effectively work.

./configure now has the following switches:

--enable-bebob build BeBoB support (default=yes)
--enable-motu build Motu support (default=no)
--enable-dice build DICE support (default=no)
--enable-metric-halo build Metric Halo support (note: completely useless)

(default=no)

--enable-rme build RME support (note: completely useless)

(default=no)

--enable-bounce build Bounce device support (default=no)
--enable-all-devices build support for all supported devices (default=no)

these now turn on/off compilation effectively.

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