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

Revision 415, 11.5 kB (checked in by pieterpalmers, 16 years ago)

ieee1394service:
- implemented 64bit compare-swap-lock operation (needed for DICE)
- small name change of (un)registerARMhandler to (un)registerARMHandler

iavdevice.h:
- made the stream start/stop functions return bool instead of int
- updated function documentation for consistency and to reflect changes

BeBoB avdevice:
- replaced the 2 fixed streamprocessor pointers with a 2 vectors of streamprocessors
- implemented the 'snoop mode' (cannot be activated yet)

libstreaming:
- removed unused 'type' attribute from AmdtpPortInfo? & children

mh_avdevice, motu_avdevice, rme_avdevice:
- replaced m_1394service with m_p1394service for consistence

maudio_avdevice.cpp:
- removed unused code

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